Solved

Simple Macro - Remove hardcoded Spreadsheet name

Posted on 2011-02-16
3
269 Views
Last Modified: 2012-06-21
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
Comment
Question by:Patrick O'Dea
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Runrigger earned 500 total points
ID: 34906511
Private Sub test()
Dim wkbTarget As Workbook

    Set wkbTarget = ActiveWorkbook
   
    wkbTarget.Activate
   
   


End Sub
0
 
LVL 11

Expert Comment

by:Runrigger
ID: 34906518
ActiveWorkbook = your BOOK_A, I am assuming that the macro is run from BOOK_A?
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 34906779
Great , thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question