Solved

How would I correct the following VBA code to edit an Excel file for column J?

Posted on 2011-02-25
1
378 Views
Last Modified: 2012-05-11
I am developing an Access 2003 application using an Excel workbook.

How would I correct the following VBA code to edit an Excel file for column J as follows:

Private Sub StartDoc(filename)
 Dim xlApp As Object
 Dim xlWS As Object
 
 'open excel template
 Set xlApp = CreateObject("excel.application")

 xlApp.Workbooks.Open (filename)
 xlApp.Visible = True

 Set xlWS = xlApp.ActiveWorkbook.Worksheets
 
 xlWS.Columns.AutoFit
 xlApp.ScreenUpdating = True
 xlApp.ActiveWorkbook.Save
 
 xlWS.Range("J2:J65535").NumberFormat = "#,##0.00"
 
 xlApp.ScreenUpdating = True
 Set xlApp = Nothing
 
End Sub
0
Comment
Question by:zimmer9
1 Comment
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34985337
Private Sub StartDoc(filename)
 Dim xlApp As Object
 Dim xlWS As Object
 
 'open excel template
 Set xlApp = CreateObject("excel.application")

 xlApp.Workbooks.Open (filename)
 xlApp.Visible = True

 Set xlWS = xlApp.ActiveWorkbook.Worksheets(1)  ' set the xlWS to Sheet1
 
 xlWS.Columns.AutoFit
 xlApp.ScreenUpdating = True

 
 xlWS.Range("J2:J65535").NumberFormat = "#,##0.00"
 
 xlApp.ScreenUpdating = True

 xlApp.ActiveWorkbook.Save
 Set xlApp = Nothing
 
End Sub
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now