wb.Name Like VBA Not Working the first time

Iron Contributor

Hello,

 

I had actually created another topic for this issue then thought it was fixed. However, turns out it's not.

 

The code below doesn't work first time the workbook is opened. If I close it and re-open it works. How can I fix this?

 

 

 

Sub CopyRAWMMP()
Application.DisplayAlerts = False
Dim Ct As Long
For Each wb In Application.Workbooks
    If Trim(LCase(wb.Name)) Like "data-*" Then
        Ct = Ct + 1
        wb.Activate
        Exit For
    End If
Next wb
    If Ct = 0 Then
    MsgBox "MSG"
     Exit Sub
    End If
    
    Range("A2:N2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy
    Workbooks("Real Time.xlsm").Activate
    Worksheets("Raw MMP").Activate
    Range("RawMMP[Date]").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Application.DisplayAlerts = True
End Sub

 

 

 

 

Immediate window doesn't recognize that the workbook is opened. I was advised that the workbook is opening in a different instance. But I don't even know what that means.

 

I'd really appreciate your help.

 

 

2 Replies
What *exactly* happens the first time you open the file?
Thank you for your response. I missed that I got a response. I hadn't actually thought of that since I was using an errorhandler and now for the life of me, I can't reproduce the error. I'll try on a different computer.