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
The Matrix
News and Events 1869 5
Sticky: Old Doordarshan Serials ! Your Pick ? ( 1 2 3 ... Last )
Filmi Gupshup 195434 193
And we say there is no racism in Canada ( 1 2 3 ... Last )
Life 28498 154
DRIVER’S HANDBOOK NOTES
Just Landed 5541 2
Take ur time and be a computer man
Science & Technology 1567 1
Top Eight Reasons NOT to immigrate to Canada ** ( 1 2 3 ... Last )
Jobs 65424 324
It's a Flat World, After All
News and Events 1881 0
New Immigrant To Canada, Is Calling It Quits! ( 1 2 3 )
Life 6683 15
Top Eight Reasons NOT to immigrate to Canada ( 1 2 3 4 )
Moving Soon 9236 27
Interesting Article About Canada
General 2239 1
Tech help needed
Science & Technology 1386 2
Leaving Canada behind
Life 2248 1
Retail dilemma ( 1 2 )
General 3091 7
Social Darwinism-Survival of the Fittest & Trickle-down Economics ( 1 2 3 ... Last )
News and Events 39261 229
Lease agreement- Problem at the end of lease ( 1 2 3 )
Real Estate & Mortgages 9226 20
Something to start the weekend fun...
Have Fun! 3134 4
Dark Side of Dubai !
General 3643 4
President Obama's speech at Cairo University ( 1 2 )
General 1855 7
The Best Answers to Tough Interview Questions ( 1 2 3 4 )
Jobs 10481 24
Wikileaks: India Cables ( 1 2 )
Our Native Country! 3596 13
TN Visa to Green Card ( 1 2 3 4 5 )
USA 9558 31
quesiton on buying business of convenience store ( 1 2 3 4 )
Business 8797 22
TGIF They say it is true.
Have Fun! 2682 0
Run Excel Macro from Access
Science & Technology 2426 5
WHODATHUNKIT ( 1 2 3 )
General 9191 17
 


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.