Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

set active sheet to current file

Posted on 2009-05-19
1
Medium Priority
?
179 Views
Last Modified: 2012-05-07
I've written some code to read a range of cells from an excel file, as below.
Now I need to paste this into the file in which the macro is running.
How to I set the active workbook/sheet to this?


excelFileSource = "C:\\Documents and Settings\\file1.xls"
On Error Resume Next
 
Set excelApplication = GetObject(, "Excel.Application")
If Err = 429 Then
    Set excelApplication = CreateObject("Excel.Application")
End If
 
Set excelWorkbookSource = excelApplication.Workbooks.Open(excelFileSource)
excelWorkbookSource.Sheets("mySheet").Activate
' select the range to copy
ActiveSheet.Range("C3:C74").Select
Selection.Copy
 
'???

Open in new window

0
Comment
Question by:allelopath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 24424517
ThisWorkbook always refers to the workbook that contains the code.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

722 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