Solved

set active sheet to current file

Posted on 2009-05-19
1
172 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
Comment Utility
ThisWorkbook always refers to the workbook that contains the code.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Checkbox Notification 3 22
AutoFilter Delete not keeping Headers? 2 12
Excel VBA - open a DataValidation dropdown 6 20
Excel 6 16
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

10 Experts available now in Live!

Get 1:1 Help Now