Solved

run excel function from access

Posted on 2013-05-24
11
403 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Outlook Free & Paid Tools
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

786 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