473,671 Members | 2,228 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need assistance with this Excel MACRO in ACCESS

13 New Member
'actually I have a macro that exports multiple querys or table into many excel spreadsheet with multiple worksheets.
'but this is just to test the Excel Macro to work on the exported files.
'is there any way to create just one RunCode that will work with for all of these files in a ACCESS Macro?

Expand|Select|Wrap|Line Numbers
  1. Function testfunction()
  2.  
  3. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Customers", "C:\Users\Juan\Desktop\test\Macrofolder\combine.xlsx", True
  4.  
  5.    Dim XL As Object
  6.  
  7.     Set XL = CreateObject("Excel.Application")
  8. 'XL.Workbooks.Open "C:\Users\Juan\Desktop\test\Macrofolder\combine.xlsx"
  9.  
  10.    XL.Workbooks.Open "C:\Users\Juan\Documents\acom split.xlsm"
  11.  
  12.    'what do I need to type in order for this macro to work on the transferspreadsheets? because it runs on itself.
  13.  
  14.      XL.Run "acom split.xlsm!acomsplit"
  15.  
  16.            End Function
What this Excel Macro does is split the worksheets based on the first column starting in Cell A2 into tabs. if there is anyway to do this in Access than relying on Excel Macro that would be greatly appreciated.
Dec 19 '11 #1
7 1757
preciouslife73
13 New Member
I thought I was getting better but it failed after several research. What is wrong with the code below? The error messages in RunCode says that it cant compile. What this Excel Macro does is split the worksheets based on the first column starting in Cell A2 into tabs. if there is anyway to do this in Access than relying on Excel Macro that would be greatly appreciated.
Expand|Select|Wrap|Line Numbers
  1. Function runmacro()
  2.  Dim xl As Object
  3.  Set xl = CreateObject("Excel.Application")
  4.  
  5.  With Excel.Application
  6.  .Visible = True
  7.  .Workbooks.Open "C:\Users\Juan\Desktop\test\Macrofolder\combine.xlsx"
  8.  .Workbooks.Open "C:\Users\Juan\Documents\Acom Split.xlsm"
  9.  .Windows("C:\Users\Juan\Documents\Acom Split.xlsm").Visible = True
  10.  .Run "Acom Split.xlsm!ACOMSplit"
  11.  .Windows("C:\Users\Juan\Documents\Acom Split.xlsm").Visible = False
  12.  .ActiveWorkbook.Close savechanges:=True
  13.  .Workbooks("Acom Split.xlsm").Close False
  14.  
  15.  
  16. .Quit
  17.  End With
  18.  
  19.  Set xl = Nothing
  20.  
  21.  End Function
  22.  
Dec 19 '11 #2
NeoPa
32,569 Recognized Expert Moderator MVP
PreciousLife73:
'is there any way to create just one RunCode that will work with for all of these files in a ACCESS Macro?
This is the only thing you posted that looks like a question. I have no idea what you mean by a RunCode, but it is certainly possible for a single piece of code in an Access project to work on multiple Excel files.

You include so little helpful information that it's hard to post anything that may be more helpful to you at this stage. You should understand that a piece of code isn't a question. The question is (or in this case perhaps is not) in the text.
Dec 19 '11 #3
preciouslife73
13 New Member
What I meant by RunCode is the functions that run the module. Alright, given the logic that I have provided in the thread. You stated that one piece of code "can" work with multiple excel. I am more interested in learning this as well. My understanding is based on your statement, ACCESS can open all Excel spreadsheets in a folder and perform the Excel Macro on each of them, correct? You did provide me the automation and the references has already been ticked. It is not really working. But i would like to change the script to make it more generic by identifying the folder rather than specific spreadsheet. Lets refer back to the VB that I just posted, why it is not firing the function name runmacro() in RunCode portion of the MACRO? It state that the function has error compiling. At first i thought maybe the reference tool was not checked but it is.
Dec 20 '11 #4
preciouslife73
13 New Member
I actually got it to work! See code below. However two questions, rather than running the macro on specified Excel file, what do i need to type to get it to work in all excel files in a folder? Question number two, sometimes I have a blank worksheet called Sheet1 with no data, and the next tab has a sheetname with data, the issue is the code is not looping through the entire workbook and skipping any blanks.
Expand|Select|Wrap|Line Numbers
  1. Function RunMacro()
  2.   Dim objExcel As Object
  3.   Set objExcel = CreateObject("Excel.Application")
  4.  
  5.   With objExcel
  6.     .Workbooks.Open "C:\Users\Juan\Documents\Acom Split.xlsm"
  7.     .Workbooks.Open "C:\Users\Juan\Desktop\test\Macrofolder\combine.xlsx"
  8.     .Run "'ACOM Split.xlsm'!ACOMSplit"
  9.     .ActiveWorkbook.Close savechanges:=True
  10.   End With
  11.  
  12.   Set objExcel = Nothing
  13.  
  14. End Function
Dec 20 '11 #5
NeoPa
32,569 Recognized Expert Moderator MVP
Let's go back to the start. We need a single question, explained clearly. You have now thrown much explanation but very little of it clear, and what seems to be the case is that you had problems (which you don't specify) compiling but you sorted those out and now you'd like to ask two more.

I haven't even caught up with the original question yet. Furthermore, only one question may be asked per thread. I can't even tell if the two follow-up questions should be allowed as a clarification of the first question as that's not even clear enough.

Moving on to processing multiple files from a single folder is not something I even want to start with you as it requires an understanding of the importance of clarity and clear understanding that you are illustrating mean little to you. You need to get the basics of asking a question clearly right before I'll even consider going there. Does that make sense?
Dec 21 '11 #6
preciouslife73
13 New Member
I understand. I would like to consider this matter closed. I was able to resolve the two questions. I will make sure I am more clear in any future inquiries. Thank you so much for bearing with me.
Dec 21 '11 #7
NeoPa
32,569 Recognized Expert Moderator MVP
I understand how difficult many people find it to express themselves, and especially anything technical, clearly. I make the point (and often repeat it), not to criticise you, but because I also understand how much benefit you can reap from developing the skill.

Anyway, I'm glad you've got yourself a solution and wish you the best of luck with your project :-)
Dec 21 '11 #8

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

Similar topics

2
11102
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
2081
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
1810
by: phong.lee | last post by:
Hello all, i'm new at this. I need some assistant in transferring data from excel to access. I created a macro that basically gather all the necessary data that i need to bring into access. I also created a table in access with the correct columns to store the data from excel. Is there a way in VBA code that i can write so that when the data that i need can be automatically transfer into my access table? Thank you
6
9854
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. My code is: Sub Run_Excel_Macro() Dim xls, xlWB As Object
0
986
by: mazelx | last post by:
Hi there, I'm searching a way to export Excel data to access... So i thought to do like this : Excel -> Dataset -> Access Is that the best way to do it? I have big excel files (multi-sheets, and up to 5000 rows), so it doesn't have to be too time-consuming...
1
2266
by: John Overton | last post by:
I have a need to run an Excel Macro from inside Access. Is this possible with Access 2003 to Excel 2003?
1
9867
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.
3
4218
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...
16
5173
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub Storage_Click() On Error GoTo Err_Storage_Click
1
6191
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA generated Excel spreadsheet from an Access Module. I can create the spreadsheet, button, and I have the macro to insert into command button. But I am not sure how to assign the macro to the button in the access module. Set xlApp =...
0
8390
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
8911
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
8819
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...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2808
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.