Export Module Using Macro -
i'm stepping through code export module using this post, nothing happens. there security setting allow vba permission export module?
i'm copying few tabs workbook new workbook, tabs have macros lead broken links. around want move module , re-associate macro. if can't work copy whole workbook , delete info don't want in destination.
here's code above post:
public sub copymodule(sourcewb workbook, strmodulename string, targetwb workbook) ' description: copies module 1 workbook ' example: copymodule workbooks(thisworkbook), "module2", ' workbooks("food specials rolling depot memo 46 - 01.xlsm") ' notes: if module copied exists, removed first, ' , afterwards copied dim strfolder string dim strtempfile string dim fname string if trim(strmodulename) = vbnullstring exit sub end if if targetwb nothing msgbox "error: target workbook " & targetwb.name & " doesn't exist (or closed)", vbcritical exit sub end if strfolder = sourcewb.path if len(strfolder) = 0 strfolder = curdir ' create temp file , copy "module2" strfolder = strfolder & "\" strtempfile = strfolder & "~tmpexport.bas" on error resume next fname = environ("temp") & "\" & strmodulename & ".bas" if dir(fname, vbnormal + vbhidden + vbsystem) <> vbnullstring err.clear kill fname if err.number <> 0 msgbox "error copying module " & strmodulename & " workbook " & sourcewb.name & " workbook " & targetwb.name, vbinformation exit sub end if end if ' remove "module2" if exits in destination workbook targetwb.vbproject.vbcomponents .remove .item(strmodulename) end ' copy "module2" temp file destination workbook sourcewb.vbproject.vbcomponents(strmodulename).export strtempfile targetwb.vbproject.vbcomponents.import strtempfile kill strtempfile on error goto 0
end sub
Comments
Post a Comment