473,769 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export from Access to Excel and Run Macro already saved

19 New Member
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
1 4249
Tim Botsford
1 New Member
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
11108
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, I know how to do this. I'm preferring to keep the Excel instance invisible, but while the macro is running, it would be nice to see some sort of progress indicator. (By the way, here's basically what the Excel macro is doing: it's opening...
0
2087
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 converted Access macro can do the same thing as the Excel macro does when i open the Excel file. Can anybody give me a hint? Thanks in advance! Alex
3
7557
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 DoCmd.OpenQuery "qry_delete FCL" DoCmd.OpenQuery "qry_temp FCL"
4
18242
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", "D:\Test.xls", True
1
9871
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 much, John O.
1
10504
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 trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
0
1069
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 File, but when I run the macro it just saves as my text in the first folder it finds. Is there a way of doing this without using VB as Im gettng confused with that. Thanks !! &!!.xls
3
4230
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 that is the same as a 'Tracking Number' (the primary key) of my Access Table. The output from excel would access this record and update the field. I currently have a macro to create new records in the table, but I am not sure if there is a way to...
1
1676
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 reachable. Therefore, we should bear in mind that I have no knowledge of how this database was initially set up. Also, I have no programming experience whatsoever and only managed to do what I've done because of J_Goddard's post to a thread I...
2
2432
by: Access user | last post by:
My apologies for crossposting this, but I did not get any response in microsoft.public.access http://groups.google.com/group/microsoft.public.access/browse_thread/thread/4929214ae589afd9/b11bf56313b894d4?lnk=st&q=access+export+to+excel#b11bf56313b894d4 The specific problem is mentioned in the above post, but here is a basic description of the problem. When using saved queries that are used as part of a union query, the UNION query...
0
9586
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.