473,406 Members | 2,713 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.

VB Script that copies a VBA function

18
Hi,

I searched google to see if there's something that can help me achieve what I wanted to do, but couldn't find any. What I want to achieve is to write a VB script that can copy the code written on the "beforeSave" functionality. And then, writes a macro based on the content of the copied code.

Is this implementation possible?

Thanks.
Aug 3 '11 #1
2 1467
irGed
18
just found out that creating macro on excel using vbscript is doable, just the copying of the "beforeSave" function left.
Aug 3 '11 #2
irGed
18
I have solved the problem but not sure if this is the best way to achieve this, if anyone has a better solution, please help me.

as for the code, I have exported the VB Component that contains the desired function and then I used a third-party tool to modify the generated export file and then I imported it with another excel.

for the export code:

Expand|Select|Wrap|Line Numbers
  1. Dim ArgObj, inputExcel, outputFile
  2. Set ArgObj = WScript.Arguments 
  3.  
  4. 'First parameter input file
  5. inputExcel = ArgObj(0) 
  6. 'Second parameter output file
  7. outputFile = ArgObj(1) 
  8.  
  9. Set objExcel1 = CreateObject("Excel.Application")
  10.     objExcel1.DisplayAlerts = 0
  11. Set objWorkbook1 = objExcel1.Workbooks.Open(inputExcel)
  12.     objWorkbook1.VBProject.VBComponents("ThisWorkbook").Export (outputFile)
  13.     objWorkbook1.Save
  14.     objExcel1.Quit
  15.     'objExcel2.Quit
  16. Set    objExcel1 = Nothing
  17.  
and for the import code:

Expand|Select|Wrap|Line Numbers
  1. Dim ArgObj, inputExcel, outputFile
  2. Set ArgObj = WScript.Arguments 
  3.  
  4. 'First parameter VALIDATION file
  5. inputExcel = ArgObj(0) 
  6. 'Second parameter input file
  7. inputFile = ArgObj(1) 
  8.  
  9. Set objExcel1 = CreateObject("Excel.Application")
  10.     objExcel1.DisplayAlerts = 0
  11. Set objWorkbook1 = objExcel1.Workbooks.Open(inputExcel)
  12. Set VBComp = objWorkbook1.VBProject.VBComponents("Module1")
  13. objWorkbook1.VBProject.VBComponents.Remove VBComp
  14. objWorkbook1.VBProject.VBComponents.Import (inputFile)
  15.     objWorkbook1.Save
  16.     objExcel1.Quit
  17. Set    objExcel1 = Nothing
  18.  

Thanks.
Aug 3 '11 #3

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

Similar topics

0
by: deko | last post by:
I use this script to keep count of visits to my site - it's on every page in the site. <?php $file = '/home/post/public_html/viscount'; if ($counter = @file ($file)) { $line = each($counter);...
2
by: Matt | last post by:
I have a function that I call from an HTML page to open a pop-up window. I would like to make the height and width as parameters but I jeep getting an "Object Expected" javascript error. I am not a...
3
by: Mark Kurten | last post by:
in the visual studio .NET samples that come with the product, why do javascript functions all have the parameters below. Even though, the event (like Onclick) which is calling it doesn't have any...
2
by: Max | last post by:
Please, could anyone tell me, how can I call directly the function in vb script after I registered it with RegisterClientScriptBlock? thanks Ma
4
by: robert.waters | last post by:
Hello, When the following page is executed in IE6, it generates script errors ('object expected') for any function that is declared in an external ..js file. Why is this???? This code works in...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
13
by: Jake Barnes | last post by:
I saw this sentence: "The last stage of variable instantiation is to create named properties of the Variable object that correspond with all the local variables declared within the function." ...
10
by: vipinc | last post by:
Hi guys, In my script, I need to switch to another user to execute a command which I don't have the privilege to run. Actually the script copies a file from one directory to another. The script...
7
by: rsculthorp | last post by:
I need help with my scripts. I am currently running a configuration script with multiple If Then statements using grep to check for the existance of a particulare set of text. If grep returns a null...
2
by: printline | last post by:
Hi all I have a problem with a form script. The form script should do the following: When a user selects a value from a drop down list and hits the "next" button it should take him to a...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.