Solved

set active sheet to current file

Posted on 2009-05-19
1
173 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
1 Comment
 
LVL 92

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Outlook Free & Paid Tools
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now