I ran a macro as below:
Sub Macro1()
'
' Macro1 Macro
'
'
Range("D7").Select
ActiveSheet.OLEObjects.Add(Filename:= _
"C:\Documents and Settings\rakshiar\Desktop\\Operating+System+Concepts.pdf" _
, Link:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer\{AC76BA86-7AD7-FFFF-7B44-AB0000000001}\PDFFile_8.ico", _
IconIndex:=0, IconLabel:="Operating+System+Concepts.pdf").Select
End Sub
And trying to convert it to VBScript code as follows:
excel = WIN32OLE.new('Excel.Application')
excel.visible = true
wb=excel.workbooks.open("E:\\WIPData\\Ruby\\Scripts\\GSL_File_DownLoad.xlsx")
wbs= wb.Worksheets(1)
wbs.cells(rows,2).values = wbs.OLEObjects.Add(,full_path,False,True, IconFileName:= _
"C:\WINDOWS\Installer\{AC76BA86-7AD7-FFFF-7B44-AB0000000001}\PDFFile_8.ico",_
IconIndex:=0,"Operating+System+Concepts.pdf")
But now could not understand how and what to put to the IconIndex and IconFileName argument?
I have .pdf,.tif,.docs,docx,.gif etc extions files which I need to attach to the Excel column using script. So at runtime how would I get values like "C:\WINDOWS\Installer\{AC76BA86-7AD7-FFFF-7B44-AB0000000001}\PDFFile_8.ico" for .pdf files?
Please help me here for the same.
You can use variables like this
Set ol = ws.OLEObjects.Add(, FileToBeinserted, False, True, icoFile, icoIndex,lbl)and before executing the above statement, simply identify what type of file you are inserting and then set the path to the relevant icon fileicoFileHere is a sample (TRIED AND TESTED) which works for selected extensions. Please amend as applicable