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 1698 3
Waiting time for spouse visa after interview ? ( 1 2 )
Ask Immigration Expert 5064 10
Waiting for Visa
Family Class 1682 2
caips CODING PLEASE HELP
Independent Category 1367 1
New Features for canadiandesi.ca
Science & Technology 1800 1
Immigration File Accessed!
Ask Immigration Expert 1732 4
FILE NO FOR PR FILE FROM BUFFALO?????????????
Independent Category 1575 3
How to delete hyperlink on WEB/EXCEL ?
Science & Technology 1143 3
Tech help needed
Science & Technology 1226 2
Sending Documents after due date
Independent Category 1680 2
Alert MSN IM Virus
Science & Technology 1076 0
what is a .pps file?
Science & Technology 1079 6
Burning a DVD ( 1 2 )
General 1530 9
student visa question
Student Visa 1720 3
Urgent - regarding Landing to Canada
Independent Category 1337 4
Urgent
Ask Immigration Expert 1230 1
Income tax return for Investors (stocks)....
Financial Planning 1729 1
How to open 'cda' file
Science & Technology 1180 1
Software Engieer and his wife
Have Fun! 1744 0
File type
Science & Technology 1360 2
Run Excel Macro from Access
Science & Technology 2280 5
Import data through button
Science & Technology 2157 3
Power point update from Excel
Science & Technology 2754 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.