+ Reply to Thread
Results 1 to 3 of 3

Problem running excel macro from vbs file

Hybrid View

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    phoenix, az
    MS-Off Ver
    Excel 2010
    Posts
    10

    Problem running excel macro from vbs file

    I have a report that runs and creates some csv files. I have managed to create a macro and its saved into the personal.xlsb file. What I need to do is somehow run this from a batch file to open the csv, run the macro, and then save the csv and close excel without saving the xlsb.

    I tried to run it from a vbs file which can be run from a command line, but it wont run my macro as it says its not available or macros are disabled. I made sure in trust center to enable all macros.


    this is the code that is saved in a vbs file.

    Option Explicit
    
        LaunchMacro
    
        Sub LaunchMacro() 
          Dim xl
          Dim xlBook      
          Dim sCurPath
    
            sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
            Set xl = CreateObject("Excel.application")
            Set xlBook = xl.Workbooks.Open(sCurPath & "\logins-computer-domain.com.csv", 0, True)      
            xl.Application.Visible = True
            xl.Application.run "C:\Documents and Settings\login\Application Data\Microsoft\Excel\XLSTART\personal.xlsb!Module1.Reports"
            xl.DisplayAlerts = False        
            xlBook.saved = True
            xl.activewindow.close
            xl.Quit
    
            Set xlBook = Nothing
            Set xl = Nothing
    
    End Sub

    thanks in advance!
    Chris
    Last edited by cheezehead; 09-06-2012 at 06:29 PM. Reason: added code

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,636

    Re: Best way to Automate this - Excel to run macro

    Thanks for Δtitle and code tags
    Last edited by protonLeah; 09-07-2012 at 01:33 AM.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-09-2012
    Location
    phoenix, az
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Problem running excel macro from vbs file

    ok all fixed up.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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