Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Run Excel Macro from VBS

Run Excel Macro from VBS

I am trying to find a macro to open Excel and run a macro.  I have tried the following script and while Excel does open and the macro starts it does not complete.  Of course the macro has been tested and runs when executed "normally".

Set xlObj = CreateObject("Excel.application")
xlobj.Visible = True ' Remove comment mark " ' " to see spreadsheets open
xlObj.Workbooks.Open "Z:\My Virtual Machines data\office\current EOD data\QP EOD data\daily stock price -0bar.xls"

xlObj.Run "macro1"

xlObj.ActiveWorkbook.Saved = False xlObj.ActiveWindow.Close            
[end code]   

I will be happy to provide any additional info if required.

RE: Run Excel Macro from VBS

The run would run the macro synchroneously. What then is there in the "macro"?

Alse is there such thing as xlObj.ActiveWindow???

RE: Run Excel Macro from VBS


Macro code as follows (line that crashed macro is noted):

Sub macro1()
' Ticker Import Function
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;Z:\My Virtual Machines data\VM find stock signals\office\EOD data\complete list current fundamental.txt", Destination:= _
        .Name = "ticker"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
      End With
' QP Data Copy
    Range("B2", Range("B2").End(xlToRight)).Copy
    Selection.End(xlDown).Offset(0, 1).Select
    Range(Selection, Selection.End(xlUp)).Select
    Application.CutCopyMode = False

' Remove_Errors

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Range("A1:H65536").Sort Key1:=Range("C1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _


Cells.Find(What:="N/A").Activate '<<<< THIS IS THE STATEMENT THAT FAILS


Range(Selection, Selection.End(xlToRight)).Select

Range(Selection, Selection.End(xlDown)).Select


' New Worksheet Name, save as: daily stock price 1bar.csv
    Application.DisplayAlerts = False
    Dim W1 As Workbook
    Set W1 = Workbooks.Add(xlWBATWorksheet)
    W1.Sheets("Sheet1").Range("A1:G10000") = _
    ActiveWorkbook.SaveAs Filename:="c:\EOD data\daily 0bar.csv", FileFormat:=xlCSV
' Save and close open Workbook(1)
    Dim Wb1 As Workbook
    For Each Wb1 In Workbooks
    If Wb1.Name <> ThisWorkbook.Name Then
    Wb1.Close savechanges:=True
    End If
    Next Wb1
' Close open Workbook(Master)
End Sub

Thanks for any thoughts you might have

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close