Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm almost there thanks to your help. There's just one last hangup from
making this code flawless. I have code that works fine for the first of nine iterations, Region1 through Region9. The misnamed file is identified, found, I double-click on it when the window pops up and the file is renamed correctly. The problem I'm having is on the second iteration, what I call Region2, the window that pops up not the correct folder. It's the folder that popped up for Region1. I have to be able to specify which folder opens when the Application.GetOpenFilename line is executed. It's like there is some default path being saved as whatever the last path was. I'm going to add some constants, which are actually based on these cell references Region1BulkID = Worksheets("Run Report").Cells(5, 3) Region1BulkPrefix = Left(Worksheets("Run Report").Cells(5, 3), 3) Region2BulkID = Worksheets("Run Report").Cells(5, 5) Region2BulkPrefix = Left(Worksheets("Run Report").Cells(5, 5), 3) in my application, so you can copy the code and try it if that will help. The values are being assigned correctly when I run my macro. Here's the code for Region1, which is working fine. ' Check to see if the Bulk Report is named correctly Const Region1BulkPrefix = "744" ' This is set in my macro by a cell reference Const Region1BulkID = "744560" ' This is set in my macro by a cell reference BulkReportPath = "\\fileserver\Data\Global\TaskorderDocuments\0 00\" & Region1BulkPrefix _ & "\" & Region1BulkID & "\" ' this is the Path BulkReportFileName should be in ' path is correctly set as \\fileserver\Data\Global\TaskorderDocuments\000\74 4\744560\ If dir(BulkReportPath & BulkReportFileName) = "" Then ' test if file is where it should be MsgBox "The Bulk Report is misnamed" & vbNewLine & vbNewLine & "Double click the Bulk _ Report in the" & vbNewLine & "next window and it will be renamed", vbInformation Line1: OldBulkReportFileName = Application.GetOpenFilename("(*bulk*.xls), *bulk*.xls") If OldBulkReportFileName < False Then ' change the name of the file Name OldBulkReportFileName As BulkReportPath & BulkReportFileName Else MsgBox "You did not select a workbook.", vbInformation GoTo Line1: End If End If Then I do some more macro stuff to complete the work for Region1 and I come into the Region2 portion of the code. It's basically the same code, only the variables for BulkReportPath are different due to the use of Region2 folder specs. Here's what I have for Region2 code: ' Check to see if the Bulk Report is named correctly Const Region2BulkPrefix = "744" ' This is set in my macro by a cell reference Const Region2BulkID = "744803" ' This is set in my macro by a cell reference BulkReportPath = "\\fileserver\Data\Global\TaskorderDocuments\0 00\" & Region2BulkPrefix _ & "\" & Region2BulkID & "\" ' this is the Path BulkReportFileName should be in ' path is correctly set as \\fileserver\Data\Global\TaskorderDocuments\000\74 4\744803\ If dir(BulkReportPath & BulkReportFileName) = "" Then ' test if file is where it should be MsgBox "The Bulk Report is misnamed" & vbNewLine & vbNewLine & "Double click the Bulk _ Report in the" & vbNewLine & "next window and it will be renamed", vbInformation Line2: OldBulkReportFileName = Application.GetOpenFilename("(*bulk*.xls), *bulk*.xls") If OldBulkReportFileName < False Then ' change the name of the file Name OldBulkReportFileName As BulkReportPath & BulkReportFileName Else MsgBox "You did not select a workbook.", vbInformation GoTo Line2: End If End If As you can see, this is nearly identical for Region1 and will be for all nine regions once this works. The problem is that when I execute the Application.GetOpenFilename line for Region2, the folder that gets opened is the same one that I had opened in Region1. I don't want the user to have to search for this folder, I want the macro to open it. Do you know why this is happening and how to fix it? I'm so close I can taste it. This path thing is all that's in my way now thanks to your help. Don |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Check File name for its existance in a folder | Excel Programming | |||
Check for file in folder | Excel Programming | |||
Save file in a new folder, but create folder only if folder doesn't already exist? | Excel Programming | |||
open file from folder save in new folder | Excel Programming | |||
check if file is in particular folder | Excel Programming |