我有以下代码,我正在使用这些代码从计算机中选择一个文件,并将其作为OLE对象附加到我的Excel工作表中。要选择文件,用户单击用户窗体中的命令按钮,这会打开选择对话框。成功附加文件后,按钮会将其颜色更改为浅绿色,但不会这样做。感谢有关此问题的帮助。
谢谢!
下面是我的代码,如下:
'ACTIVE IN TEST 2
Sub InsertTradeLicense()
Dim iconToUse As String
Dim fullFileName As String
Dim FNExtension As String
fullFileName = Application.GetOpenFilename("*.*, All Files", , , , False)
If fullFileName = "False" Then
Exit Sub
End If
FNExtension = Right(fullFileName, Len(fullFileName) - _
InStrRev(fullFileName, "."))
Select Case UCase(FNExtension)
Case Is = "TXT"
iconToUse = "C:\Windows\system32\packager.dll"
Case Is = "XLS", "XLSM", "XLSX"
iconToUse = "C:\Windows\Installer\{91140000-0011-0000-0000-0000000FF1CE}\xlicons.exe"
Case Is = "PDF"
iconToUse = "C:\Windows\Installer\{AC76BA86-1033-F400-7761-000000000004}\_PDFFile.ico"
Case Else
iconToUse = "C:\Windows\system32\packager.dll"
End Select
'****** ds added *******
Dim curFile As OLEObject
On Error Resume Next 'continue even if error so we can analyze if curFile is
an object or not...
Set curFile = ActiveSheet.OLEObjects.Add(Filename:=fullFileName, Link:= _
False, DisplayAsIcon:=True, IconFileName:= _
iconToUse, IconIndex:=0, IconLabel:=fullFileName)
If curFile Is Nothing Then
'not an object, didn't work. turn diff color
MsgBox ("File was not attached successfully!")
ATL.BackColor = &H8080FF
Else
'curFile is NOT nothing; it is an object so it worked!
MsgBox ("File attached successfully!")
ATL.BackColor = &H80FF80
End If
On Error GoTo 0 'resume normal error catching
'****** end ds ********
End Sub