Solved

Format Excel Columns as Text from MS Access using VBA

Posted on 2013-10-25
5
7,966 Views
Last Modified: 2013-10-27
I need to format two Excel columns as text from MS Access using VBA. Any thoughts.
0
Comment
Question by:shieldsco
[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
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39601875
You need to open the Excel Workbook and then format two columns?

The following will open PATH/Name.xls and format Columns A through B as Text on the first Sheet:

    Set objApp = CreateObject("Excel.Application")
        objApp.Visible = True
        Set wb = objApp.Workbooks.Open("PATH/Name.xls", True, False)
    
    wb.Sheets(1).Range("A:B").NumberFormat = "@"

Open in new window


Change the PATH/Name.xls to your Excel File, the number of the Sheet, then the Column(s).
0
 

Author Comment

by:shieldsco
ID: 39603761
Works good but how do I save the workbook and close the application
0
 
LVL 18

Accepted Solution

by:
Steven Harris earned 500 total points
ID: 39603935
    Set objApp = CreateObject("Excel.Application")
        objApp.Visible = True
        Set wb = objApp.Workbooks.Open("PATH/Name.xls", True, False)
    
    wb.Sheets(1).Range("A:B").NumberFormat = "@"
    
    wb.SaveAs "PATH/Name.xls"
    wb.Close
    Set objApp = Nothing

Open in new window

0
 

Author Comment

by:shieldsco
ID: 39604226
How do I close the Excel application?

Private Sub Command0_Click()
 Set objApp = CreateObject("Excel.Application")
        objApp.Visible = True
        Set wb = objApp.Workbooks.Open("C:\Users\ShieldsCo\Documents\Change Text.xlsx", True, False)
   
    wb.Sheets(1).Range("A:B").NumberFormat = "@"
    wb.Save
    wb.Close
 
    Set objApp = Nothing
   
End Sub
0
 

Author Closing Comment

by:shieldsco
ID: 39604262
Thanks
0

Featured Post

Industry Leaders: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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