PDA

View Full Version : execute macro in another workbook, only works when interactive



evilaid
10-23-2011, 02:40 AM
I've got such a annoying problem and i no longer know what to do..

I've got two workbooks.
From the first one i make a call for a macro in the second workbook. What the macro in the second workbook does is only that it makes a printout of a sheet (in the same book)..
This works fine when i open the the second workbook and interactivitley start the printout macro, but nothin happens when calling macro from the other workbook.

I tested and the macro executes correctly but printout never happens, i also made an error handler and it gives no errors.

I noticed the same problem if i in the printout macro try to create and save a new excelfile...

So...
When calling macros in another workbook macros run correctly but printout and filecreation never seems to happen?

Much appreciate any help or suggestions
Best regards

GTO
10-23-2011, 03:46 AM
Greetings evilaid,

Welcome to vbaexpress!

I would suggest zipping the two files (or example files if the files are large and/or contain sensitive data) so we can see what you mean.

Mark

evilaid
10-23-2011, 04:14 AM
Hi Mark..

Thanks for your replay..

The files are availble at
w3.heta.se/xl/xl.zip

The problem is just the same if i trie creating a new file within the print macro??


I got an error trying to attach a link this replay? anyhow, the "w3" is triple w

mdmackillop
10-23-2011, 06:55 AM
Try one of these methods

Sub Test2()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = Workbooks.Open(ActiveWorkbook.Path & "\print.xls")
wb.Sheets(1).PrintOut
wb.Close False

End Sub

Sub Test3()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = Workbooks.Open(ActiveWorkbook.Path & "\print.xls")
Application.Run "Print.xls!DoPrint"
wb.Close False

End Sub