+ Reply to Thread
Results 1 to 4 of 4

Help with VBS running an excel macro

  1. #1
    Registered User
    Join Date
    04-09-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    17

    Help with VBS running an excel macro

    Good Afternoon,

    I have an outlook job that downloads an excel file then runs a VB Script whenever a particular email arrives in my inbox. The VBS in turn runs a macro from my PERSONAL.xlsb file that modifies the downloaded xls file. I use the PERSONAL.xlsb as my universal macro housing unit and I often have it open as I run macros from it manually and daily.

    My dilemma is that, so long as my PERSONAL.xlsb file is closed, the outlook/vbs/vba process runs fine. If I have PERSONAL.xlsb open at the time the outlook job runs, the VBS will execute but won't complete the VBA because the xlsb file is open and it prompts for a readonly, at which case, if I am at my PC I can click it and the process will finish, but if I happen to be afk for a while, it will not run and process the changes made in the VBA macro.

    How can I have this run regardless of whether or not my PERSONAL.xlsb file is opened or closed? Below are the scripts I have in each process.

    VBS that works as long as PERSONAL.xlsb is closed.
    Option Explicit
    On Error Resume Next

    ExcelMacroExample

    Sub ExcelMacroExample()

    Dim xlApp

    Set xlApp = CreateObject("Excel.Application")

    xlApp.Application.Visible = False
    xlApp.DisplayAlerts = False
    xlApp.Run "'C:\FILEPATH\PERSONAL.XLSB'!Macro1"
    xlApp.DisplayAlerts = True
    xlApp.Quit

    Set xlApp = Nothing

    End Sub


    This is the beginning of the excel macro that edits the downloaded file.
    Sub Macro1()
    '
    ' Macro1 Macro

    Dim xlBook
    Set xlBook = Workbooks.Open("U:\FILEPATH\Kester.xlsx", 0, True)

    xlBook.Application.Visible = False
    Workbooks.Application.DisplayAlerts = False
    xlBook.Application.DisplayAlerts = False

    "Do All Edits and Such"


    Your help is much appreciated!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Help with VBS running an excel macro

    Can you call the Personal macro from the current instance of Excel? Calling the macro from a second instance of Excel is what triggers the prompt.

    Please Login or Register  to view this content.
    This would hide the workbook that Macro1 opens.
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-09-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Help with VBS running an excel macro

    Thanks for the reply Alphafrog. So while I was able to incorporate your suggestions into my excel macro and get that working, the VBS recommendation you have wont call the macro when the PERSONAL.xlsb is opened or closed. Using my VBS I can call the xls macro (with your inclusions) and it will run fine so long as the xlsb file is closed. It seems the trouble may be pointed to mine and your VBS. Neither of them call the xls macro when xlsb is opened. Any other suggestions?

    For reference, this is your suggestion that is not working at all.
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Help with VBS running an excel macro

    Are you running your ExcelMacroExample from Excel or Outlook? If Excel, are you saying it wouldn't call the Personal Macro1 at all, or it called it but still has the same Read-only issue?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. code works running in visual basic editor but not when running from Excel macro
    By smporco in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2016, 05:44 PM
  2. [SOLVED] Excel Hangs when running Macro unless resource monitor open on top of excel??????
    By JimBobBowie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2014, 10:55 AM
  3. error when running MS Word macro commands in Excel macro
    By bsapaka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2014, 01:30 PM
  4. Replies: 2
    Last Post: 11-26-2012, 08:33 AM
  5. Replies: 7
    Last Post: 07-28-2011, 11:11 AM
  6. Replies: 3
    Last Post: 07-06-2006, 02:45 PM
  7. [SOLVED] Running a macro outside of Excel
    By Zakynthos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2005, 06:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1