473,395 Members | 1,335 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,395 software developers and data experts.

Need assistance with this Excel MACRO in ACCESS

'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 1745
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,556 Expert Mod 16PB
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
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
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,556 Expert Mod 16PB
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
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,556 Expert Mod 16PB
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
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: 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...
6
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. ...
0
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...
1
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
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...
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...
16
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...
1
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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...
0
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...

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.