Solved

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

Posted on 2011-02-25
1
379 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

895 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

12 Experts available now in Live!

Get 1:1 Help Now