Consulting

Results 1 to 12 of 12

Thread: Rationalize my import / export code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Aug 2004
    Location
    Manchester UK
    Posts
    16
    Location

    Rationalize my import / export code

    Guys,

    I have this code that I am using to export and import modules into a workbook to be upgraded.

    2 things.

    1 - This line - Application.Dialogs(xlDialogActivate).Show IS NOT making the selected workbook acitive. I need to do this so I can define TWB as the target workbook

    2 - I'm sure I could put a couple of loops in my code to reduce it a bit.

    Thanks in advance . .
    Bob

    Private Sub upgrade()
        'Select target workbook
        Dim TWB As Workbook 'Target Workbook
        Dim UWB As Workbook 'Upgrade Workbook
        Dim FName As String 'temp filename for export / import
        Application.ScreenUpdating = False
        Set UWB = ActiveWorkbook
        MsgBox "Please select the Workbook to upgrade" & vbNewLine & "from the following list . . ." & vbNewLine & "(Click OK to show)"
        Application.Dialogs(xlDialogActivate).Show
        Set TWB = ActiveWorkbook
        'delete existing modules in Target WB
        Dim VBComp As VBComponent
        On Error Resume Next
        With TWB
             Set VBComp = ThisWorkbook.VBProject.VBComponents("frmsavewr")
             ThisWorkbook.VBProject.VBComponents.Remove VBComp
             Set VBComp = ThisWorkbook.VBProject.VBComponents("frmsavecr")
             ThisWorkbook.VBProject.VBComponents.Remove VBComp
             Set VBComp = ThisWorkbook.VBProject.VBComponents("Mdl_Sendmail")
             ThisWorkbook.VBProject.VBComponents.Remove VBComp
             Set VBComp = ThisWorkbook.VBProject.VBComponents("Mdl_spellcheck")
             ThisWorkbook.VBProject.VBComponents.Remove VBComp
             Set VBComp = ThisWorkbook.VBProject.VBComponents("Mdl_Toolbar")
             ThisWorkbook.VBProject.VBComponents.Remove VBComp
        End With
        'import / export code
        With UWB
             FName = .Path & "\code.txt"
             .VBProject.VBComponents("frmsavewr").Export FName
        End With
        TWB.VBProject.VBComponents.Import FName
        With UWB
             FName = .Path & "\code.txt"
             .VBProject.VBComponents("frmsavecr").Export FName
        End With
        TWB.VBProject.VBComponents.Import FName
        With UWB
             FName = .Path & "\code.txt"
             .VBProject.VBComponents("Mdl_Sendmail").Export FName
        End With
        TWB.VBProject.VBComponents.Import FName
        With UWB
             FName = .Path & "\code.txt"
             .VBProject.VBComponents("Mdl_spellcheck").Export FName
        End With
        TWB.VBProject.VBComponents.Import FName
        With UWB
             FName = .Path & "\code.txt"
             .VBProject.VBComponents("Mdl_Toolbar").Export FName
        End With
        TWB.VBProject.VBComponents.Import FName
        Application.ScreenUpdating = True
    End Sub
    Last edited by Aussiebear; 12-21-2024 at 05:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •