+ Reply to Thread
Results 1 to 3 of 3

Macro won't run - WrkBk name keeps changing

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    349

    Macro won't run - WrkBk name keeps changing

    The following code unhides and copies the "Data" tab from a doc called Aliant Call Profile Report (End of Day) and then pastes it into a tab called NBReport Data on a document that doesn't have a set name so I've used ActiveSheet.Paste. The problem I have is now Aliant Call Profile Report (End of Day) is no longer the name. Excel seems to want to continue adding (1),(2),(3), etc... to the end of my filename. I know about the excel /unregserver but that did not solve my problem. Is there a way to modify my code to account for the fact that my filename won't stay the same?

    Windows("Aliant Call Profile Report (End of Day) .xls").Activate
    Sheets("Data").Visible = True
    ActiveWorkbook.Activate
    Sheets("Data").Select
    Range("A1:Z533").Activate
    Selection.Copy
    ThisWorkbook.Activate
    Sheets("NBReport Data").Select
    ActiveCell.Cells.Select
    ActiveSheet.Paste
    Sheets("Control").Select
    Range("A1").Select
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Macro won't run - WrkBk name keeps changing

    ThisWorkbook and Activeworkbook are probably considered the same workbook. You will have to use the destination workbook name for thisworkbook

  3. #3
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    349

    Re: Macro won't run - WrkBk name keeps changing

    Thought I'd share the code that actually worked for me. Thanks for your reply though Dave.

    Sub GetNBReport()
    Application.ScreenUpdating = False
    For Each w In Workbooks
    If w.Name Like "*Aliant Call Profile Report*" Then
    Windows(w.Name).Activate
    Exit For
    End If
    Next w
    Sheets("Data").Visible = True
    ActiveWorkbook.Activate
    Sheets("Data").Select
    Range("A1:Z533").Activate
    Selection.Copy
    ThisWorkbook.Activate
    Sheets("NBReport Data").Select
    ActiveCell.Cells.Select
    ActiveSheet.Paste
    Sheets("Control").Select
    Range("A1").Select
    Windows(w.Name).Close
    Application.ScreenUpdating = True
    End Sub
    Last edited by Wheelie686; 11-26-2012 at 04:46 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1