Access to Excel back to Access

Jonbob

Board Regular
Joined
Feb 6, 2003
Messages
160
I have code that Runs Macros is Access, then opens up Excel, then goes back to the same Access Database to run more macros. Everything works fine, except when it goes back to access, it opens up a new Access window and calls the same database again. How do I make it work so it does back to the Access window already open? I believe the problem is with my Excel code- see below:

Sub open_access2()
Dim DB As Object
Dim pth As String

pth = ActiveWorkbook.Path & "\Jewelry Labels.mdb"
Set DB = CreateObject("Access.Application")

DB.Visible = False
DB.OpenCurrentDatabase (pth)
DB.Docmd.RunMacro "Print_Labels" ' Macro name in DataBase

Set DB = Nothing

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Take a look at the GetObject function instead of CreateObject.

Can you explain what you are actually trying to do? There could be another way to do it.
 
Upvote 0
I have to pull information from a SQL Database in Access, manipulate in Excel, and then print out labels in Access.
 
Upvote 0
What manipulation is being done in Excel?

Can it not be done in Access?
 
Upvote 0
I figured it out.. I changed my Access code..see below...

Agreed- there probably was a easier way- like doing this all in Access, but I was too far into the project to turn back.

Option Compare Database

Function Run_Labels()

Dim obj_xl As Object
Dim x As Variant

' Set Excel information

Set obj_xl = CreateObject("Excel.Application")
With obj_xl.Application
.Visible = True

' Open the Workbook

.Workbooks.Open "G:\Everyone\Jewelry Labels.xls"

'Run macro

x = .Run("run_labels_excel")
.Quit

End With

DoCmd.RunMacro "Print_Labels"

End Function
 
Upvote 0

Forum statistics

Threads
1,221,814
Messages
6,162,135
Members
451,744
Latest member
outis_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top