Solved

run excel function from access

Posted on 2013-05-24
11
425 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
[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
  • 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
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!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

717 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