?
Solved

Starting excel

Posted on 2000-01-26
4
Medium Priority
?
176 Views
Last Modified: 2010-05-02
Can anybody tell me how I can open the FileName1 xls so that I can manipulate it's contents.  The code below works fine if the excel application is open.  If it's not alreday open the code will not work.
 
Set xApp = New Excel.Application
  Filename1 = App.Path & "\SSB" & x & ".xls"
  FileName2 = App.Path & "\SSB" & x & ".hld"
  Set xWork = GetObject(Filename1)
   xWork.Application.Columns("F:L").Select
   xWork.Application.Range("F2").Activate
   xWork.Application.ActiveCell.Activate
   xWork.Application.Selection.NumberFormat = "@"
   xWork.SaveAs FileName2, xlCSV

Thanks!

Regards
0
Comment
Question by:vgru
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2389005

Filename1 = App.Path & "\SSB" & x & ".xls"
Set xApp = Getobject(Filename1)
set xSheet = xApp.worksheets(1)
This should start Excel if it isn't running, or use an existing instance of Excel if it is running.

You then work with xSheet, like:

xSheet.Columns("F:L").Select

Hope this helps.

Wes
0
 
LVL 2

Accepted Solution

by:
adityau earned 150 total points
ID: 2391781
Use the following code. Hope, it works.

Set xApp = New Excel.Application
Filename1 = App.Path & "\SSB" & x & ".xls"
FileName2 = App.Path & "\SSB" & x & ".hld"
Set xApp = New Excel.Application
xApp.Workbooks.Open filename1
xApp.Visible = True
Set xsheet = xApp.worksheets(1)
xWork.Application.Columns("F:L").Select
xWork.Application.Range("F2").Activate
xWork.Application.ActiveCell.Activate
xWork.Application.Selection.NumberFormat = "@"
xApp.SaveAs FileName2, xlCSV
xApp.Quit
Set xWork=Nothing
Set xWork = Nothing
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2392727
You both might want to know that you don't need to use the "select" and "activate" methods when using Excel as an automation server.

xsheet.range("F2").numberformat = "@"

will do the trick without all those "select" and "activate" methods.

adityau:

Correct me if I'm wrong, but I don't think your code will work because xWork isn't set to an object variable.  Rather than referencing xWork.Application (which has to be causing an error) you should be referencing xSheet

You might want to make sure your code is bulletproof before posting it as an answer and locking up the question.

Wes
0
 
LVL 2

Expert Comment

by:adityau
ID: 2392774
I am sorry.

Set xsheet = xApp.worksheets(1)

should be

Set xWork = xApp.worksheets(1)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question