PDA

View Full Version : چگونگی فعال کردن اتومات رفرنس در هنگام اجرای یک برنامه



somayeh1361
یک شنبه 20 تیر 1395, 07:36 صبح
سلام به اساتید
کمک فوری :متفکر::متفکر::متفکر:
من یه برنامه دارم که با اکسس 2010 نوشته شده همانطور که مطلع هستید برای اجرای فایلهای اکسل باید رفرنس microsoft excel object libary در اکسس فعال بشه که بسته به ورژن اکسس فرق می کنه 12 یا 13
حال مشکل اینه اگه در اکسس 2010 این رفرنس فعال بشه کسی که از ورژن پایین تر استفاده می کنه با مشکل مواجه می شه چون با عدم شناسایی رفرنس مواجه میشه
چطور میشه برنامه رو تنظیم کرد که رفرنس متناسب با نوع اکسس تنظیم بشه
ممنون میشم راهنمایی بفرمائید

amirzazadeh
یک شنبه 20 تیر 1395, 09:09 صبح
سلام
از اين لينك ها كمك بگيريد:
http://stackoverflow.com/questions/5593588/add-references-programatically

(http://stackoverflow.com/questions/5593588/add-references-programatically)

somayeh1361
یک شنبه 20 تیر 1395, 10:23 صبح
سلام دوست عزیز ممنون از راهنمایی تون
میشه روش استفاده از این کدها را بگید که چگونه ازش استفاده کنم یا کجا باید کپی بشه
ممنون
در ضمن لینک دوم باز نمیشه

amirzazadeh
یک شنبه 20 تیر 1395, 11:57 صبح
لينك دوم
https://support.microsoft.com/en-us/kb/310803 (http://stackoverflow.com/questions/5593588/add-references-programatically)

كدها اصولا در رويداد لود فرم آغازين برنامه بايد قرار داده بشه.

somayeh1361
یک شنبه 20 تیر 1395, 21:08 عصر
دوستان میتوان یک نمونه که از این کدها در اون استفاده شده باشه و خودشون تست کرده باشند بذارید

somayeh1361
دوشنبه 21 تیر 1395, 08:20 صبح
سلام صبح بخیر از دوستانی که در خصوص مشکل یادشده در تایپیک راهنمایی نمودند متشکرم دوستان اگر در خصوص نحوه استفاده از این کدها راهنمایی بفرمایند ممنون میشم
If Dir("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe") <> "" And Not refExists("excel") Then
Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe")
End If
If Dir("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") <> "" And Not refExists("excel") Then
Access.References.AddFromFile ("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe")
End If
If Dir("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe") = "" And Dir("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe") = "" Then
MsgBox ("ERROR: Excel not found")
End If
And the refExists references the following function:
Private Function refExists(naam As String)Dim ref As ReferencerefExists = FalseFor Each ref In References If ref.Name = naam Then refExists = True End IfNextEnd Function



1 down vote

Here is a code sample, which checks for broken references. I know this is not the whole solution for you, but it will give you some clues how to do it.



Public Function CheckRefs() On Error GoTo Handler Dim rs As Recordset Dim ref As Reference Dim msg As String For Each ref In Application.References ' Check IsBroken property. If ref.IsBroken = True Then msg = msg & "Name: " & ref.Name & vbTab msg = msg & "FullPath: " & ref.FullPath & vbTab msg = msg & "Version: " & ref.Major & "." & ref.Minor & vbCrLf End If Next ref If Len(msg) > 0 Then MsgBox msg Exit Function Handler: ' error codes 3075 and 3085 need special handling If Err.Number = 3075 Or Err.Number = 3085 Then Err.Clear FixUpRefs Else rs.Close Set rs = Nothing End IfEnd Function Private Sub FixUpRefs() Dim r As Reference, r1 As Reference Dim s As String ' search the first ref which isn't Access or VBA For Each r In Application.References If r.Name <> "Access" And r.Name <> "VBA" Then Set r1 = r Exit For End If Next s = r1.FullPath ' remove the reference and add it again from file References.Remove r1 References.AddFromFile s ' hidden syscmd to compile the db Call SysCmd(504, 16483)End Sub
Here is an example - it check for certain references - deleting them and importing the Access 2000 variant. Just to make sure all clients use the same (lowest) version of the dependencies
Sub CheckReference()' This refers to your VBA project. Dim chkRef As Reference Dim foundWord, foundExcel As Boolean foundWord = False foundExcel = False ' Check through the selected references in the References dialog box. For Each chkRef In References ' If the reference is broken, send the name to the Immediate Window. If chkRef.IsBroken Then Debug.Print chkRef.Name End If If InStr(UCase(chkRef.FullPath), UCase("MSWORD9.olb")) <> 0 Then foundWord = True End If If InStr(UCase(chkRef.FullPath), UCase("EXCEL9.OLB")) <> 0 Then foundExcel = True End If If InStr(UCase(chkRef.FullPath), UCase("MSWORD.olb")) <> 0 Then References.Remove chkRef ElseIf InStr(UCase(chkRef.FullPath), UCase("EXCEL.EXE")) <> 0 Then References.Remove chkRef End If Next If (foundWord = False) Then References.AddFromFile ("\\pathto\database\MSWORD9.OLB") End If If (foundExcel = False) Then References.AddFromFile ("\\pathto\database\EXCEL9.OLB") End If End Sub

somayeh1361
دوشنبه 21 تیر 1395, 08:36 صبح
این هم فایل راهنماش

somayeh1361
دوشنبه 21 تیر 1395, 11:45 صبح
سلام دوباره ظهر بخیر دوستان کسی پیدا نمیشه به ما کمک کنه

somayeh1361
دوشنبه 21 تیر 1395, 11:50 صبح
سلام کمک کمکککککککککککککک

somayeh1361
چهارشنبه 23 تیر 1395, 08:05 صبح
کمککککککککککککککککککککککک ککککککککککککک