Export macro with location referenced in Cell

YolandaCB

New Member
Joined
Feb 18, 2022
Messages
1
Office Version
  1. 2013
Platform
  1. MacOS
I have written this macro below. I get an error on the Workbooks(ThisWorkkBook).VBProject.VBComponents("Module1").Export strTempFile.
How do I define this?

Sub CopyModule()

Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim Path As String
Dim FName As String
Dim wb2 As Workbook
Dim strModuleName As String
Dim strTempFile As String



Set wb1 = ThisWorkbook
Set ws1 = wb1.Worksheets("BackUp")
Path = ws1.Range("B14")
FName = Path & "\" & ws1.Range("B16")

strTempFile = strFolder & "~tmpexport.bas"

'On Error Resume Next '<= disabled for Debugging purpose

Workbooks(ThisWorkkBook).VBProject.VBComponents("Module1").Export strTempFile '<= changed
Workbooks(FName).VBProject.VBComponents.Import strTempFile '<= changed

Kill strTempFile
On Error GoTo 0

For Each VBComp In VBProj.VBComponents

'Check the type of the object make sure its a code module
If VBComp.Type = vbext_ct_StdModule Then

'Let the user know it's continuing
Debug.Print VBComp.Name
Debug.Print VBComp.Type

'Create the file name to export the file
Filename = "C:\Users\Alex\Desktop\Files\" + WBName + "_" + VBComp.Name + ".bas"

'Export the file.
VBComp.Export Filename:=Filename

End If
Next

'Close the active workbook
ActWrkBook.Close




'Turn off screen updates
Application.ScreenUpdating = True

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top