vba xlsm open hidden

Posted on 2009-12-17
Last Modified: 2012-05-08
Hi Experts

I have a xlsm file with some code inside. I would like to open the xlsm file. Then the code inside the xlsm file is running, and the xlsm file will save and close it self. As it is now i'm opening the file like this:
Application.FollowHyperlink "C:\UK\PP_BF.xlsm"
But the I get a message box the ask me if i want to open the file. I don't want this box to appear, and if possible the excel file should be open hidden.

Can someone help me with this?  
    LVL 9

    Expert Comment

    With following the hyperlink you give the control to system. Try this (you can change xlApp.Visible to false later) , but please note the application will not exit, so if the excel sheet does not quit the application then the excel process stays in memory.

    Dim xlBook  As Object
    Dim xlApp   As Object

    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Open( "C:\UK\PP_BF.xlsm")
    xlApp.Visible = true
    Set xlApp = Nothing
    Set xlBook = Nothing
    LVL 9

    Expert Comment


    Set xlBook = xlApp.Workbooks.Open( "C:\UK\PP_BF.xlsm",,False)

    to open it in read write mode

    Author Comment

    just to be sure, the code inside the excel file, will it run and be done before the code continues and set the xlBook and xlApp to nothing?
    LVL 9

    Accepted Solution

    No, it is asynchronous. Therefore be sure to do an application.quit in your excel macro when it exits. The lines Set xlApp = Nothing and Set xlBook = Nothing do not affect your macro, but only release the memory in vba.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
    Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now