LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Check for file in folder, if not there, open folder to rename

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check File name for its existance in a folder Muk Excel Programming 9 December 19th 06 07:52 AM
Check for file in folder Les Stout[_2_] Excel Programming 2 October 11th 06 07:08 PM
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
open file from folder save in new folder tim64[_3_] Excel Programming 20 June 17th 05 07:58 PM
check if file is in particular folder nikolaosk[_10_] Excel Programming 2 October 18th 03 04:25 PM


All times are GMT +1. The time now is 06:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"