Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

724 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