Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Solved: Excel VBA Exporting Modules


(!)

scotty718's Avatar
scotty718 scotty718 is offline
Member with 185 posts.
THREAD STARTER
 
Join Date: Nov 2010
Experience: Intermediate
09-Sep-2011, 11:18 AM #1
Solved: Excel VBA Exporting Modules
Hi All,

Having some trouble exporting modules from code. Not sure why. Any help would be appreciated. I am getting Run-time error '50012' Method 'Export' of object '_VBComponent' failed. I am using an .xls workbook in Excel 2007.

My code is below, but the export breaks even when I do this:

Code:
strPath = "C:\ReplaceTaxCode" 
ActiveWorkbook.VBProject.VBComponents("ToolsA").Export "\" & strPath
Full Code Here:
Code:
Public Sub ReplaceCode()

Dim wkbCode, wkbReplace As Workbook
Dim strPath
Dim VBAEditor As VBIDE.VBE
Dim objProject As VBIDE.VBProject
Dim objComponent As VBIDE.VBComponent

Set wkbCode = ThisWorkbook
Set VBAEditor = Application.VBE
Set objProject = VBAEditor.ActiveVBProject

strPath = "C:\ReplaceTaxCode"

For Each objComponent In objProject.VBComponents
    objProject.VBComponents(objComponent.Name).Export "\" & strPath
Next

End Sub
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,464 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
12-Sep-2011, 06:29 AM #2
That's quite clear

objProject.VBComponents(objComponent.Name).Export & "\" & strPath

The syntax is incorrect, it must be something like

objComponent.Export strPath & "\" & objComponent.Name & ".bas"

Google is great!
scotty718's Avatar
scotty718 scotty718 is offline
Member with 185 posts.
THREAD STARTER
 
Join Date: Nov 2010
Experience: Intermediate
12-Sep-2011, 01:47 PM #3
Thank you Hans.

I actually have pulled the following code I found (using google ) - http://www.cpearson.com/excel/vbe.aspx. It's the code called CopyModule. Its great, except it is hanging at a certain point. I hope I can eliminate the hang.
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,464 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
12-Sep-2011, 03:11 PM #4
You will have to be a little more specific, have you tried debugging? Just go thorugh the module step by step and see where it hngs or goes wrong?
You could put an aposttrophe in from of all the On Error Resume Next lines so that these will not be triggered, that way you will gen an error message, then click on degub an you will be taken to that line of code and you can see what goes wrong.
scotty718's Avatar
scotty718 scotty718 is offline
Member with 185 posts.
THREAD STARTER
 
Join Date: Nov 2010
Experience: Intermediate
12-Sep-2011, 03:13 PM #5
Sorry. I wasn't more specific. I know where it was hanging, but didn't understand why, but wasn't really asking for help I actually just ran it again, and voila!, works like a charm! Some great, great code, IMHO.
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,464 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
12-Sep-2011, 03:18 PM #6
Good for you. Congrats

Last edited by Keebellah; 12-Sep-2011 at 03:19 PM.. Reason: Type-Oooo
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2