• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Simple Macro - Remove hardcoded Spreadsheet name

See attached code.
This code was generated by "Recording" key strokes.  (I think)

The sequence is as follows;
1. Open workbook "BOOK_A".

2. Run the macro below which opens workbook "BOOK_B" (and copies data from "BOOK_B")

3. The data from "BOOK_B" is then pasted into "BOOK_A".

Question: I do not want to hardcode the "BOOK_A" workbook in the VBA.  Since I begin in BOOK_A how can I simply re-activate this book without specifying the hard-coded name.


This is the problem VBA line (I merely want to re-activate the sheet that I started in).

Windows("BOOK_A").Activate
Sub TBImportIRE()
'
' TBImportIRE Macro
'
    Windows("BOOKB").Activate
    Sheets("IRE TB - Current").Select
    Cells.Select
    Selection.Copy
    Windows("BOOK_A").Activate
    Range("A1").Select
    ActiveSheet.Paste
    Range("A1").Select
End Sub

Open in new window

0
Patrick O'Dea
Asked:
Patrick O'Dea
  • 2
1 Solution
 
RunriggerCommented:
Private Sub test()
Dim wkbTarget As Workbook

    Set wkbTarget = ActiveWorkbook
   
    wkbTarget.Activate
   
   


End Sub
0
 
RunriggerCommented:
ActiveWorkbook = your BOOK_A, I am assuming that the macro is run from BOOK_A?
0
 
Patrick O'DeaAuthor Commented:
Great , thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now