Results 1 to 9 of 9

Running Excel Macro in Batch File

Threaded View

  1. #3
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Running Excel Macro in Batch File

    Edit this in notepad and save as a .vbs file extension. You can continue with Excels' Object Model using the instance of xlApp you have created.

    Const Overwrite = True
    Const SaveChanges = True
    strSource = "f:\a\axys3\users\brandon\test.txt"
    strDest = "C:\Users\btoney\Desktop\IMRF\test.txt"
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    oFSO.CopyFile strSource, strDest , Overwrite
    set xlApp = CreateObject("Excel.Application")
    xlApp.visible = TRUE
    xlApp.Workbooks.Open strDest
    set wb = XlApp.Workbooks(1)
    wb.Activesheet.Range("A1:C4").Select
    xlApp.Selection.Font.Bold = True
    wb.Close SaveChanges
    xlApp.Quit
    Added a little more code so you can see how to edit the sheet, save, close and quit the app. The font.Bold will have no effect if you save as a .txt file though, it's just there so you can see how to use the object model.
    Last edited by Neil_; 08-16-2016 at 01:59 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need macro that opens .txt file in excel, run macros and save file in batch
    By khalidness in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2014, 11:00 AM
  2. Batch file to run excel macro
    By shotta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2013, 12:48 PM
  3. [SOLVED] Need help batch running an excel macro on .csv files and saving back to the same .csv
    By OutKlast in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-31-2013, 09:16 PM
  4. Getting an exception while running a batch file from vb script
    By sharabh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-25-2012, 01:02 AM
  5. Running batch file
    By walduxas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2009, 08:07 AM
  6. Running a batch file from Excel
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-21-2008, 09:47 AM
  7. Run Excel Macro through Batch file
    By LJi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2005, 02:05 PM

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