Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:56:59+00:00 2026-06-17T22:56:59+00:00

I ran a macro as below: Sub Macro1() ‘ ‘ Macro1 Macro ‘ ‘

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:57:00+00:00Added an answer on June 17, 2026 at 10:57 pm

    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 file icoFile

    Here is a sample (TRIED AND TESTED) which works for selected extensions. Please amend as applicable

    '~~> Sample icons for relevant files
    Const pdfIco = "D:\Temp\icons\ARROWS\AARROW.ico"
    Const wrdIco = "D:\Temp\icons\ARROWS\ANYWHERE.ico"
    Const TiffIco = "D:\Temp\icons\ARROWS\ARROW1.ico"
    Const OtherFormat = "D:\Temp\icons\ARROWS\ARROW1A.ico"
    
    Dim Xl, Wb, Ws, ol, FileToBeInserted, lbl
    
    Set Xl = CreateObject("Excel.Application")
    Xl.Visible = True
    
    Set Wb = Xl.Workbooks.Add
    Set Ws = Wb.Sheets(1)
    
    '~~> Let user select a file
    FileToBeInserted = Xl.GetOpenFilename("All Files (*.*), *.*")
    
    '~~> Check if the user selected a file
    If FileToBeInserted <> False Then
        '~~> Get the file name for the label
        lbl = GetFileName(FileToBeInserted)
    
        icoIndex = 0
    
        '~~> I am testing for just 3 extensions. Amend as applicable
        Select Case GetFileExtn(FileToBeInserted)
        Case "PDF"
            icoFile = pdfIco
        Case "DOCX", "DOC"
            icoFile = wrdIco
        Case "Tiff"
            icoFile = TiffIco
        Case Else
            icoFile = OtherFormat
        End Select
    
        '~~> Create the object
        Set ol = Ws.OLEObjects.Add(, FileToBeInserted, False, True, icoFile, icoIndex, lbl)
    End If
    
    '~~> Function to get the File extention
    Function GetFileExtn(sFile)
        GetFileExtn = Trim(UCase(Right(sFile, Len(sFile) - InStrRev(sFile, "."))))
    End Function
    
    '~~> Function to get the file name
    Function GetFileName(sFile)
        GetFileName = Left(sFile, (InStrRev(sFile, ".", -1, 1) - 1))
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just ran a Macro and got the below: Sub Macro1() ' ' Macro1
Ran into this error message while trying to select some records off a table.
I'm making my first (admittedly bad) macro with imacros and have ran into a
Ran into problem with creating custom select dropdown plugin in jQuery. I'm at the
I ran into some trouble trying to implement a smart equality test macro-type template
Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX
Ran into something interesting, want to know if I'm doing something wrong or if
I ran the convert_to_south command on my app. Everything seems to have gone fine:
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
I ran a program with different threads in two configurations a and b .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.