Solved

run excel function from access

Posted on 2013-05-24
11
411 Views
Last Modified: 2013-06-01
Hi Experts, Need some help with running the following excel function from access vba code.

Sub FormatChange()
    Range("K1:K2000").Select
    Selection.NumberFormat = "yyyymmdd"
End Sub
0
Comment
Question by:needhelpfast569
  • 5
  • 5
11 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39195095
you have to open the excel file first

Sub FormatChange()
dim xlObj as Object, xlFile as string
 xlFile="c:\somefolder\myExcel.xls"
set xlObj=createobject("excel.application")
      xlObj.workbooks.open xlFile
    with xlObj
               .worksheets("sheet1").activate
               .Range("K1:K2000").Select
               .Selection.NumberFormat = "yyyymmdd"
                .activeworkbook.save
     end with

     xlObj.quit

End Sub
0
 

Author Comment

by:needhelpfast569
ID: 39199085
hi capricorn1, That worked great cleared up the problem. But is there anyway to make it so it does not ask the user to save the changes and overwrite the existing file?

Thanks Rick
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39199220
try this


Sub FormatChange()
dim xlObj as Object, xlFile as string
 xlFile="c:\somefolder\myExcel.xls"
set xlObj=createobject("excel.application")
      xlObj.workbooks.open xlFile
    with xlObj
               .worksheets("sheet1").activate
               .Range("K1:K2000").Select
               .Selection.NumberFormat = "yyyymmdd"

               .displayalerts=false  'ADD this line

                .activeworkbook.save
     end with

     xlObj.quit

End Sub
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:needhelpfast569
ID: 39199312
Perfecxt thank you very much
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39199370
what? you are accepting your own post as the solution to your problem..
0
 

Author Comment

by:needhelpfast569
ID: 39212585
completed the task
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39212845
needhelpfast569,


it is not right that you accept your own post and forget about the expert that helped you resolve your problem..



you must give credit to whoever helped you.

..
0
 

Author Comment

by:needhelpfast569
ID: 39212862
Sorry as far as I know I gave you the whole 500 points and all the credit.  You gave me the perfect solution to the problem. If I screwed up how can I correct it?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39213002
click the Request Attention just below your original post, and ask to reopen the thread so you can correct the mistake and select the post at

http:#a39199220 

as the accepted solution
0
 

Author Closing Comment

by:needhelpfast569
ID: 39213820
Hope this fixs the problem thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Outlook Free & Paid Tools
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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…

839 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