using macro to open an excel spreadsheet

qaxooti

New Member
Joined
Apr 13, 2005
Messages
38
I am using a simulation software to open up results in an excel spreadsheet. What I basically want to do is to open up an excel spreadsheet, and then have it follow a macro to put the results on the sheet. I have already the macro data, the only problem I am having is that I can get the spreadsheet to open and format the first time, but then when I run the simulation again, only a blank sheet opens up and the macro is not run....I am very confused....I do'nt know if it some odd quirk of excel or something....also, how can you use VBA to open up an external file? The way I have currently done it is that I will open an new excel application and then use a macro the changes directories and opens up the correct file. I can't see to open up the file directly without doing that. Is there some type of command that would help me with that? Here is my code for opening the excel spreadsheet:

' =========================================================================
' Start Excel (or use existing program instance if Excel already is loaded)
' =========================================================================
Dim XL As Excel.Application, XLBook As Excel.Workbook, XLSheet As Excel.Worksheet
On Error Resume Next
Set XL = CreateObject("Excel.Application")


' Set XL = GetObject(, "Excel.Application")
' If Err.Number <> 0 Then ' Excel wasn't loaded; start it
' Err.Clear
' If Err.Number <> 0 Then
' MsgBox "Unable to load Microsoft Excel."
' Exit Sub
' End If
' End If
' Err.Clear

XL.Visible = True
' Add a new workbook with one worksheet for the chart
XL.SheetsInNewWorkbook = 1
Set XLBook = XL.Workbooks.Add
' Row = 0
' Set XLSheet = XLBook.Worksheets(1)
' XLSheet.Name = "Results"



With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Lockheed Project\F22 Sim.out", Destination:=Range("A1"))
.Name = "F22 Sim"



after this, I have more commands that will do more stuff to the spreadsheet
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
In the absence of another reply (using LL97 that doesnot have TEXT; option) :-

Perhaps you have to use
.Refresh
on the query table.
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top