Consulting

Results 1 to 4 of 4

Thread: execute macro in another workbook, only works when interactive

  1. #1
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    2
    Location

    execute macro in another workbook, only works when interactive

    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

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    2
    Location
    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
    Attached Files Attached Files
    Last edited by mdmackillop; 10-23-2011 at 06:26 AM. Reason: Files attached

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try one of these methods

    [VBA]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
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •