Consulting

Results 1 to 3 of 3

Thread: Solved: Copying Named Ranges

  1. #1
    VBAX Regular
    Joined
    Apr 2010
    Location
    Cheltenham
    Posts
    32
    Location

    Solved: Copying Named Ranges

    Hi Guys

    I need your help...again!

    I have some working code, it looks at a location for another excel document and pulls in all the worksheets.

    The problem comes when it tries to copy across the named ranges, there can be upto 20 in each of the documents im bringing into the current document and excel requires me to press "YES" to each and everyone. Is there a way to turn this off and say yes to all?

    If CheckBox1.Value = True Then
    Dim obXL As Object
    Dim wbSource As Workbook
    Dim wbTarget As Workbook
    Dim Sht As Worksheet
    Set wbTarget = ThisWorkbook
    Set wbSource = Workbooks.Open(tbFilePath) ' Pulls file path from tbFilePath box (worked better this way)
    For Each Sht In wbSource.Sheets
        Sht.Copy before:=wbTarget.Sheets(1)
    Next
    wbSource.Close ' Close the source workbook
    GoTo CarryOn
    ElseIf CheckBox1.Value = False Then
    GoTo CarryOn
    End If
    Message Received:


  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Application.DisplayAlerts = False

    If CheckBox1.Value = True Then
    Dim obXL As Object
    Dim wbSource As Workbook
    Dim wbTarget As Workbook
    Dim Sht As Worksheet
    Set wbTarget = ThisWorkbook
    Set wbSource = Workbooks.Open(tbFilePath) ' Pulls file path from tbFilePath box (worked better this way)
    For Each Sht In wbSource.Sheets
    Sht.Copy before:=wbTarget.Sheets(1)
    Next
    wbSource.Close ' Close the source workbook
    GoTo CarryOn
    ElseIf CheckBox1.Value = False Then
    GoTo CarryOn
    End If

    Application.DisplayAlerts = True
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2010
    Location
    Cheltenham
    Posts
    32
    Location
    Quote Originally Posted by xld
    [vba]

    Application.DisplayAlerts = False

    If CheckBox1.Value = True Then
    Dim obXL As Object
    Dim wbSource As Workbook
    Dim wbTarget As Workbook
    Dim Sht As Worksheet
    Set wbTarget = ThisWorkbook
    Set wbSource = Workbooks.Open(tbFilePath) ' Pulls file path from tbFilePath box (worked better this way)
    For Each Sht In wbSource.Sheets
    Sht.Copy before:=wbTarget.Sheets(1)
    Next
    wbSource.Close ' Close the source workbook
    GoTo CarryOn
    ElseIf CheckBox1.Value = False Then
    GoTo CarryOn
    End If

    Application.DisplayAlerts = True
    [/vba]
    Thanks xld, Solved!

Posting Permissions

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