Open Excel from Visio

Hey There

I used the code attached below to Open Excel from behind a button in Excel as a prroof of concept kind of thing.  Now, armed with the code snippet, I am trying to get this to work
in Visio.  However, I am not having any luck.  I get the error message "User-defined type not defined" on the first line.  Is there a refrence or library I need to add to call Excel from behind a button in Visio?

Thanks,
jimbo99999


Dim exapp As Excel.Application
    Dim exbook As Excel.Workbook
    Dim exsheet As Excel.Worksheet
    Set xlapp = CreateObject("Excel.Application")
    Set xlBook = xlapp.Workbooks.Open("C:\QualityDashboard\quality_dashboard.xls")
    Set exsheet = xlBook.Worksheets("Training")
    exsheet.Select
    xlapp.Visible = True

Open in new window

Jimbo99999Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
peakpeakConnect With a Mentor Commented:
In the VBA window in Visio, click tools and then References. Select Microsoft Excel Object library
0
 
Chris BottomleyCommented:
Hello Jimbo99999,

Alternatively the following should work in any VBA application without changes to the application itself:

Chris

Regards,

chris_bottomley
Dim exapp As Excel.Application
    Dim exbook As object
    Dim exsheet As object
    Set xlapp = CreateObject("Excel.Application")
    Set xlBook = xlapp.Workbooks.Open("C:\QualityDashboard\quality_dashboard.xls")
    Set exsheet = xlBook.Worksheets("Training")
    exsheet.Select
    xlapp.Visible = True

Open in new window

0
 
Chris BottomleyConnect With a Mentor Commented:
Jimbo99999,

MIssed a line!

chris_bottomley
    Dim exapp As object
    Dim exbook As object
    Dim exsheet As object
    Set xlapp = CreateObject("Excel.Application")
    Set xlBook = xlapp.Workbooks.Open("C:\QualityDashboard\quality_dashboard.xls")
    Set exsheet = xlBook.Worksheets("Training")
    exsheet.Select
    xlapp.Visible = True

Open in new window

0
 
Jimbo99999Author Commented:
Thanks for the tips guys.  It is working as requested by the User.

Good Day,
jimbo99999
0
All Courses

From novice to tech pro — start learning today.