I'm trying to programatically add Excel VBA references to my macro as I am trying to control powerpoint through my excel macro. Here's what I have so far, but my code appears to be adding new references rather than activating existing ones. I tried both AddFromGuid as well as AddFromFile and neither work. Does anyone know how to activate these?
Sub UpdateExcelReferences()
'// Set references to
'// Microsoft Excel 11.0 Object Library, {00020813-0000-0000-C000-000000000046}, 1, 5, C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE
'// Microsoft Office 11.0 Object Library, {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}, 2, 3, C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL
'// Microsoft PowerPoint 11.0 Object Library, {91493440-5A91-11CF-8700-00AA0060263B}, 2, 8, C:\Program Files\Microsoft Office\OFFICE11\msppt.olb
'// whose DLL types are Scripting.FileSystemObject
'// Microsoft scripting Runtime
Dim ID As Object
'On Error Resume Next
Set ID = ThisWorkbook.VBProject.References
ID.AddFromGuid "{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}", 1, 5
ID.AddFromGuid "{00020813-0000-0000-C000-000000000046}", 2, 3
ID.AddFromGuid "{91493440-5A91-11CF-8700-00AA0060263B}", 2, 8
'ID.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL]"
'ID.AddFromFile "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE]"
'ID.AddFromFile "C:\Program Files\Microsoft Office\OFFICE11\msppt.olb]"
End Sub
by: ryancysPosted on 2007-06-26 at 03:10:19ID: 19362208
You can always create Excel Object by using scripts like below and no need to add References dynamically, like:
ation") test.xls")
Dim xlsApp As Object, wb As Object, ws As Object
Set xlsApp = CreateObject("Excel.Applic
xlsApp.visible = true
Set wb = xlsApp.Workbooks.Open("C:\
Set ws = wb..Worksheets(1)
'msgbox ws.name
'...
Set ws = Nothing
wb.Close
Set wb = Nothing
Set xlsApp = Nothing
...
?