• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Switch between files using code

PSG

Member
Hi All,

I am working with three workbooks. My aim is to open two workbooks from cell values provided in my first workbook.

Alternatively activate workbook 2 and workbook 3 to copy paste data from wb2 to wb3.

I am using the below code but not able to do that. Please let me know what am I doing wrong and how this can be corrected to solve my purpose.

Thanks in advance for your expert opinion. :awesome:


Code:
Sub UpdateDataTab()
Dim FTName As String ' is my file template
Dim MFName As String 'is my master file

FTName = ActiveSheet.Range("C6").Value
MFName = ActiveSheet.Range("C5").Value

Workbooks.Open MFName
Workbooks.Open FTName

'now I want activate MFName and copy paste data to FTName.

MF.Activate ' is not working for me
 
Hi ,

Change your code slightly , as follows :
Code:
    Set master = Workbooks.Open(MFName)
    Set template = Workbooks.Open(FTName)

'  now I want activate MFName and copy paste data to FTName.

    master.Activate
MFName and FTName are strings ; when you use the Activate command , you need it to operate on a Workbook object ; this is done by using the Set command.

You can declare master and template as follows :
Code:
Dim master as Workbook , template as Workbook
Narayan
 
Back
Top