Solved

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

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

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 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