473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Export from Access to Excel and Run Macro already saved

I am new to VBA writing so bear with me here. I have been searching the web but I keep finding answers in pieces which is more confusing!

What I am trying to do is export a table from Access to Excel and run a macro (it's a formatting macro). My issue is that when Access exports the table, it resaves it and I lose the macro (The spreadsheet will be accessible to anyone so I can't just save it in the Personal workbook). When I try to copy the VBA from the macro to Access, I receive an error saying "Compile Error: Method or Data Not Found"

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenExcelExport()
  2. Dim appExcel As Excel.Application
  3. Dim appWB As Excel.Workbook
  4. Set appExcel = GetObject("My Excel File")
  5. With appExcel
  6. .Visible = True
  7. Columns("D:F").Select
  8.     Selection.Copy
  9.     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
  10.         :=False, Transpose:=False
  11.     Application.CutCopyMode = False
  12.     Selection.Style = "Currency"
  13.     Rows("1:1").Select
  14.     Selection.Delete Shift:=xlUp
  15.     Range("A1:A3").Select
  16.     Selection.Font.Bold = True
  17.     Range("A5:F5").Select
  18.     Selection.Font.Bold = True
  19.     Cells.Select
  20.     Cells.EntireColumn.AutoFit
  21.     Range("D5").Select
  22.     Selection.End(xlDown).Select
  23.     ActiveCell.Offset(2, 0).Activate
  24.     Set yRng = Range("D5", Selection.Offset(1, 0))
  25.     Selection = WorksheetFunction.Sum(yRng)
  26.     Selection.Font.Bold = True
  27.         Range("E5").Select
  28.     Selection.End(xlDown).Select
  29.     ActiveCell.Offset(2, 0).Activate
  30.     Set yRng = Range("E5", Selection.Offset(1, 0))
  31.     Selection = WorksheetFunction.Sum(yRng)
  32.     Selection.Font.Bold = True
  33.         Range("F5").Select
  34.     Selection.End(xlDown).Select
  35.     ActiveCell.Offset(2, 0).Activate
  36.     Set yRng = Range("F5", Selection.Offset(1, 0))
  37.     Selection = WorksheetFunction.Sum(yRng)
  38.     Selection.Font.Bold = True
  39.     Range("A5").Select
  40.     Cells.Select
  41.     Cells.EntireColumn.AutoFit
  42. End Sub
Aug 13 '10 #1

✓ answered by Tim Botsford

As you have found, Access overwrites the previous file when you export each time.
The Personal.wks would have been the right place to store the macro, BUT as you indicate, this is NOT the right place for 'workgroup' macros.
But use that idea and make a workbook as a 'workgroup' file (so no one can change it, or make it read-only). Save it in a shared folder that everyone that needs this macro has access. Save the macro in that workbook.
Then each person simply has to have that file open when needing to run the macro. If you assign a shortcut key sequence, they can execute that macro.
If you/they need this worksheet open at all times, their Excel autostart settings could cause it to open when starting Excel.
Just some ideas. Maybe others exist.

1 4213
As you have found, Access overwrites the previous file when you export each time.
The Personal.wks would have been the right place to store the macro, BUT as you indicate, this is NOT the right place for 'workgroup' macros.
But use that idea and make a workbook as a 'workgroup' file (so no one can change it, or make it read-only). Save it in a shared folder that everyone that needs this macro has access. Save the macro in that workbook.
Then each person simply has to have that file open when needing to run the macro. If you assign a shortcut key sequence, they can execute that macro.
If you/they need this worksheet open at all times, their Excel autostart settings could cause it to open when starting Excel.
Just some ideas. Maybe others exist.
Aug 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
0
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the...
3
by: bwhite | last post by:
I have a temp table with one row of data that I need to export into Excel. I created the export to create the xls file as follows ... Dim FileName FileName = !! DoCmd.SetWarnings False...
4
by: sunilkeswani | last post by:
I need help with exporting data from 2 access tables, into 2 existing spreadsheets in a single Excel file. Currently, I am using this code: DoCmd.TransferSpreadsheet acExport, 8, "Table1",...
1
by: jdoverton | last post by:
Hey, I routinely import an Excel file, operate on several columns and export it as a separate file. I need to be able to run an Excel Macro from my Access VBA. Any Suggestions?/ Thanks...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
0
by: LB79 | last post by:
Hello, Im trying to get a file to automatically export to Excel (which it is), I want the name and location of the file to be dynamic. Ive tried putting the below in the Macro where it says Output...
3
by: redbenn | last post by:
Hello, I am trying to create an excel macro, that when clicked... a specific cell will match a record in my database, and update certain fields in this record. The Excel file will have a cell...
1
by: bmcgeoch | last post by:
To preface this post, I personally did not create the database in question. It was created by someone working for our technical support provider. That person has since left the company and is not...
2
by: Access user | last post by:
My apologies for crossposting this, but I did not get any response in microsoft.public.access ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.