Solved

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

Posted on 2011-02-25
1
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

733 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