Tech Support Guy banner
Status
Not open for further replies.

Solved: Excel VBA Exporting Modules

11K views 5 replies 2 participants last post by  Keebellah 
#1 ·
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
 
See less See more
#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.
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top