Solved

set active sheet to current file

Posted on 2009-05-19
1
174 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Formatting 3 21
MS Excel Vllokup or formula to see if a record exists... 1 22
populate Excel dropdown via ADO and VBA 6 15
Delete all empty columns using VBA 7 36
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

815 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

9 Experts available now in Live!

Get 1:1 Help Now