Open Excel from Publisher VBA

danuk1976

Board Regular
Joined
Nov 17, 2013
Messages
56
Anyone know how to open an excel file from publisher, I've searched the world for this.

This is how I open publisher from publisher
Code:
Sub openpub()

' Create new instance of Publisher.
    Dim appPub As New Publisher.Application

    ' Open publication.
    appPub.Open Filename:="C:\test.pub"

    ' Put code here to modify the publication as necessary.

    ' Close the publication.
    appPub.ActiveDocument.Close

    ' Release the other instance of Publisher.
    Set appPub = Nothing


End Sub
thanks
 
Last edited by a moderator:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Set a reference to Excel, then

Code:
Sub OpenExcel()
    Dim appXl       As Excel.Application

    Set appXl = New Excel.Application
    appXl.Open Filename:="C:\test.xlsx"
    ' do stuff
    appXl.ActiveWorkbook.Close
    Set appXl = Nothing
End Sub
 
Upvote 0
Set a reference to Excel, then

Rich (BB code):
Sub OpenExcel()
    Dim appXl   As Excel.Application

    Set appXl = New Excel.Application
    appXl.Open Filename:="C:\test.xlsx"
    ' do stuff
    appXl.ActiveWorkbook.Close
    Set appXl = Nothing
End Sub

Looked good but,,,,,,,,,,,,,,,,,,,I get

Compile error
User defined type not defined for the top line

I am user publisher 2007
 
Upvote 0
As shg said "Set a reference to Excel". In the VB Editor, click Tools-References, then choose the Microsoft Excel 12.0 Object library.
 
Upvote 0
As shg said "Set a reference to Excel". In the VB Editor, click Tools-References, then choose the Microsoft Excel 12.0 Object library.

I ticked the box for Microsoft Excel 12.0 Object library,,,
I am getting runtime error 438, object does not support this property or method and debugs to the line underlined below

any more advice appreciated


Sub OpenExcel()

Dim appxl As Excel.Application

Set appxl = New Excel.Application

appxl.Open Filename:="C:\test.xls"

' do stuff
'appXl.ActiveWorkbook.Close
'Set appXl = Nothing

End Sub
 
Upvote 0
It should read:
Code:
appxl.workbooks.open Filename:="C:\test.xls"
 
Upvote 0

Forum statistics

Threads
1,225,657
Messages
6,186,257
Members
453,347
Latest member
mrizkiii28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top