Run Excel Macro from Access


Jump to Page:
< Previous  [ 1 ]    Next >




adnancanada   
Member since: Jan 09
Posts: 107
Location:

Post ID: #PID Posted on: 09-10-15 16:45:27

I have created a macro file abc.xlsm and save it on my C drive . I want open access form and click on command button to run excel macro.

What actually I want, I want to open excel file xyz.xlsx and run macro to format my file and close it. End result my xyz.xlsx file should be formatted and close. Below this code just working on abc.xlsm and not on xyz.xlsx.


Private Sub Command0_Click()
Dim xl As Object

Set xl = CreateObject("Excel.Application";)
xl.Workbooks.Open ("C:Workabc.xlsm";)



xl.Visible = True



xl.Run ("Macro1";)


xl.activeworkbook.Close (True)
xl.Quit



Set xl = Nothing


End Sub



rajcanada   
Member since: Jul 03
Posts: 2713
Location: Kitchener, ON

Post ID: #PID Posted on: 09-10-15 21:30:55

You are opening the workbook abc.xlsm and not xyz.xlsx in the above code. So macro will run only on that workbook.

You can also get the path of the Excel file from InputBox where you choose the path of the file instead of hard coding it.

Dim Path As String
Path = InputBox( "Enter Path of Excel File" )
xl.Workbooks.Open (Path)


-----------------------------------------------------------------
Give free food http://www.thehungersite.com ||


Full House   
Member since: Oct 12
Posts: 2677
Location:

Post ID: #PID Posted on: 11-10-15 03:05:11


Hey, wssup.. who is pana sona and nana cana and soona mana are you guys all one and the same??!!

Or just pulling our legs...?

FH.



rajcanada   
Member since: Jul 03
Posts: 2713
Location: Kitchener, ON

Post ID: #PID Posted on: 11-10-15 20:44:14

I do not think there is a need to create two Excel objects. Try the code below
------------------------------------------------------------------------
Private Sub Command6_Click()
Dim xl As Object

Set xl = CreateObject("Excel.Application" )

xl.Workbooks.Open ( " C: work abc.xlsm" )
xl.Workbooks.Open ( "C: work xyz.xlsx" )

xl.Visible = True

xl.Run "abc.xlsm!Macro1"

xl.ActiveWorkbook.Close (True)

xl.Workbooks.Close

xl.Quit

Set xl = Nothing

End Sub


-----------------------------------------------------------------
Give free food http://www.thehungersite.com ||




Jump to Page: < Previous  [ 1 ]    Next >

Discussions similar to: Run Excel Macro from Access

Topic Forum Views Replies
Transfering file to another province
Ask Immigration Expert 1226 1
Download complete CAIPS code list
Independent Category 1699 3
Waiting time for spouse visa after interview ? ( 1 2 )
Ask Immigration Expert 5065 10
Waiting for Visa
Family Class 1683 2
caips CODING PLEASE HELP
Independent Category 1369 1
New Features for canadiandesi.ca
Science & Technology 1801 1
Immigration File Accessed!
Ask Immigration Expert 1733 4
FILE NO FOR PR FILE FROM BUFFALO?????????????
Independent Category 1575 3
How to delete hyperlink on WEB/EXCEL ?
Science & Technology 1144 3
Tech help needed
Science & Technology 1229 2
Sending Documents after due date
Independent Category 1682 2
Alert MSN IM Virus
Science & Technology 1077 0
what is a .pps file?
Science & Technology 1083 6
Burning a DVD ( 1 2 )
General 1533 9
student visa question
Student Visa 1721 3
Urgent - regarding Landing to Canada
Independent Category 1339 4
Urgent
Ask Immigration Expert 1231 1
Income tax return for Investors (stocks)....
Financial Planning 1732 1
How to open 'cda' file
Science & Technology 1182 1
Software Engieer and his wife
Have Fun! 1745 0
File type
Science & Technology 1365 2
Run Excel Macro from Access
Science & Technology 2281 5
Import data through button
Science & Technology 2159 3
Power point update from Excel
Science & Technology 2755 2
 


Share:
















Advertise Contact Us Privacy Policy and Terms of Usage FAQ
Canadian Desi
© 2001 Marg eSolutions


Site designed, developed and maintained by Marg eSolutions Inc.