Activate an Open File

srschicago

Board Regular
Joined
Apr 14, 2017
Messages
59
Hey Guys,


I am looping through a directory of files I need to modify. I copy daya from the open file to a temp file, modify it then copy that data back into the source file. Not the most elegant process, but easy for me.
The problem I have is activating the source file again after working in the temp file. What am I doing wrong? Hangs at the Windows(MyFullName).Activate step.
Code:
    Dim MyFile As String
    MyPath = "Z:\BOM's\EDI\"
    MyFile = Dir(MyPath)
           


'Open BOM file and select contents
    Do While MyFile <> ""
    If MyFile Like "*.xlsx" Then
    Workbooks.Open MyPath & MyFile
    Dim MyFullName As String
    MyFullName = ActiveWorkbook.FullName
    Range("A1:E1000").Select
    Selection.Copy


'Paste into TranslationTemplate
    Windows("PartID Description TranslateTemplate.xlsm").Activate
    Range("A1").Select
    ActiveSheet.Paste
....


'Copy to originating file
    Range("A2:E1000").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows(MyFullName).Activate
    Range("A2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
MyFullName = ActiveWorkbook.FullName

Change FullName to Name. The workbook you're activating is the one open in Excel, not the one on disk.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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