How to make opened workbook as active workbook

jjacks60

New Member
Joined
Jul 28, 2014
Messages
40
Code:
    strFilePath = "\\Ykf001\grpdata\PUBLIC\Operations\Converting Schedule\"  ' this could also be a constant
    strFileName = Dir(strFilePath)
    
    
    Set wbkOpen = Workbooks.Open(strFilePath & strFileName, False, True)

As you can see I have a variable workbook name, as the only way I can refer to it is knowing its the only excel file in the folder I'm accessing - so this isn't as simple as activating a known workbook name.

As it stands now this portion of the code OPENS the workbook fine - it just won't do anything in the workbook because I think I'm referring to it incorrectly.

Additionally - The sheet name with the data changes:
Currently it says August 29, before it says July 14, its variable but it is always the first sheet. For some reason when the workbook opens though it opens to the second sheet.

I need to activate the first sheet in the workbook I just opened, so that I can copy and paste a range into my "Raw Production Data" workbook.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Maybe

Code:
Set wbkOpen = Workbooks.Open(strFilePath & strFileName, False, True)
wbopen.Select
Sheet1.Select
 
Upvote 0
Maybe

Code:
Set wbkOpen = Workbooks.Open(strFilePath & strFileName, False, True)
wbopen.Select
Sheet1.Select

I tried wbOpen and I don't have anything declared for it so it didn't work.
I've tried making wbkOpen = activeworkbook, again no results.

The macro WAS working before I tried to change pastespecial to go for only visible rows. Ever since the code just stops right after I open it. I've tried cutting off the code to find out exactly where it stops - always after I set WbkOpen...

I just don't understand.
 
Upvote 0
Code:
Here is the code now [code]     Set wbkOpen = Workbooks.Open(strFilePath & strFileName, False, True)
        Sheets(1).Activate
        Set wbkOpen = ActiveWorkbook
        
        wbkOpen.Sheets(1).Range("A2").Copy
        
         Workbooks("Raw Data pRODUCTION.xlsx").Worksheets("Production Data").Range("A1").Select.PasteSpecial Paste:=xlPasteValues, _
                Operation:=xlNone, SkipBlanks:=True, Transpose:=False
                Application.CutCopyMode = False

I made some changes - neither have worked.

I had it perform Sheets(1).Activate
then Set wbkOpen = Activeworkbook

Neither worked.

I even changed the actions, but I seemingly can't work in the workbook I just opened. It IS read only BUT I performed the macro this morning fine.
 
Upvote 0
I did some tinkering so this is odd.

No matter what the file path is, where the sub is, or what the excel workbook is every single time the workbook will open then the macro will stop.

It's completely irrelevant of the action, because once that file opens the macro just stops.

Any ideas?
 
Upvote 0

Forum statistics

Threads
1,222,239
Messages
6,164,784
Members
451,914
Latest member
mdfariborz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top