Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard issue? 1

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
This code...

Code:
Sub NewSheet()

Application.ScreenUpdating = False

Dim strNewSheetName As String

    Last = Cells(Rows.Count, "A").End(xlUp).Row
For i = Last To 1 Step -1
strNewSheetName = Cells(i, "D").Value & " " & Cells(i, "C").Value

Workbooks("Web Transfer Worksheet.xlt").Activate
Sheets("Template").Visible = True

    Sheets("Template").Copy after:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = strNewSheetName

Dim strMonth As String
Dim strYear As String
Dim strDate As String

strDay = Format$(Day(Now), "00")
strMonth = Format$(Month(Now), "00")
strYear = Format$(Year(Now), "####")
strDate = strYear + strMonth + strDay

Workbooks(strDate + "*_OmniTransferErrorReport.csv").Activate

Next i

Sheets("Template").Visible = False

Application.ScreenUpdating = True

End Sub


...is throwing an error at this line...

Code:
Workbooks(strDate + "*_OmniTransferErrorReport.csv").Activate

What I can't figure out is why that doesn't work, when this does...

Code:
Sub OpenFile()

Dim strMonth As String
Dim strYear As String
Dim strDate As String

strDay = Format$(Day(Now), "00")
strMonth = Format$(Month(Now), "00")
strYear = Format$(Year(Now), "####")
strDate = strYear + strMonth + strDay

Workbooks.Open _
    ("I:\Ryan Plew\Web Transfer VBA\" + strDate + "*_OmniTransferErrorReport.csv")

End Sub

Thoughts?
 

hi,

have you looked at your string in the VB Editor. Put in a Debug.Print "I:\Ryan Plew\Web Transfer VBA\" + strDate + "*_OmniTransferErrorReport.csv"

and see what you get.
BTW, all you need
Code:
Workbooks.Open _
    ("I:\Ryan Plew\Web Transfer VBA\" & [highlight]Format(Date, "yyyymmdd")[/highlight] & "*_OmniTransferErrorReport.csv")


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


...is throwing an error at this line...


CODE
Workbooks(strDate + "*_OmniTransferErrorReport.csv").Activate
Is the workbook already open when this statement executes?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
BTW, all you need

CODE
Workbooks.Open _
("I:\Ryan Plew\Web Transfer VBA\" & Format(Date, "yyyymmdd") & "*_OmniTransferErrorReport.csv")

Thanks, Skip! Not quite sure what I was thinking with the strings.

I also updated the following...

Code:
Workbooks(Format(Date, "yyyymmdd") & "*_OmniTransferErrorReport.csv").Activate

...but am still not having any luck.

Yes, the workbook is already open.
 

And you absolutely know that it is open in the SAME INSTANCE of Excel as the workbook where your code is running?

Can you "see" THAT workbook in the VB Editor VBA Project Explorer where your code is running?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
It is open in the same instance of Excel. I can see that workbook in the Project window of the editor (both are there).
 


That error indicates an incorrect workbook name.

Use the Watch Window to observe good stuff about your ovjects & varialbes in the VB Editor faq707-4594

It should help you debug the issue.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for all your help Skip! In digging deeper, I've come upon an adequate solution.

Code:
Dim curWorkbook As Workbook
Set curWorkbook = ActiveWorkbook

I put the above code at the beginning of my routine, then changed the line in question to:

Code:
curWorkbook.Activate
 

Code:
Dim curWorkbook As Workbook
Set curWorkbook = Workbooks.Open _
    ("I:\Ryan Plew\Web Transfer VBA\" & Format(Date, "yyyymmdd") & "*_OmniTransferErrorReport.csv")


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top