LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Getting Application.GetOpenFilename to open correct folder

I'm trying to write code that checks to see if a file of a specific name
exists in a folder. If it does then I just continue with my macro. If the
file is not there or is not named correctly I need the macro to open that
folder so I can rename it.

RyanH helped me a bunch yesterday getting code written that will look in the
folder and check for me, but I'm having trouble getting the
Application.GetOpenFilename line to open the correct folder to open. I dont
want the user to have to browse for the folder when the macro already knows
what folder the file is in. It seems to be using some kind of default path
that I can't figure out how to control. This morning it opened the Personal
folder when I tried it after a fresh reboot.

This file name check occurs on nine different folders for nine different
regions, Region1 through Region9. Right now the code accurately identifies
the misnamed file, an Open window pops up but I have to browse to the correct
folder. I can then double-click on the file and the file is renamed
correctly. I like this double-click ability as it keeps the users input to a
minimum. The problem I'm having is getting the correct folder to open up. I
have to be able to specify which folder opens when the
Application.GetOpenFilename line is executed.

In Cell(5,3) on worksheet "Run Report" is the number 744560
In Cell(5,5) on worksheet "Run Report" is the number 744803

Here's the code:

'This is the name of the file I'm looking for
'and what it should be called everytime
Const BulkReportFileName = "BulkFulfillmentReport.xls"

Region1BulkID = Worksheets("Run Report").Cells(5, 3) €˜744560
Region1BulkPrefix = Left(Worksheets("Run Report").Cells(5, 3), 3) €˜744
Region2BulkID = Worksheets("Run Report").Cells(5, 5) '744803
Region2BulkPrefix = Left(Worksheets("Run Report").Cells(5, 5), 3) '744

Region1:

€˜this is the Path the file should be in for Region1
BulkReportPath = "\\fileserver\Data\Global\Taskorder _
Documents\000\" & Region1BulkPrefix & "\" & Region1BulkID & "\"

€˜check to see if the Bulk Report is named correctly
If dir(BulkReportPath & BulkReportFileName) = "" Then

MsgBox "The Bulk Report is misnamed" & vbNewLine & _
vbNewLine & "Double click the Bulk Report in the" & _
vbNewLine & "next window and it will be renamed", _
vbInformation, "The Bulk Report is misnamed"

Line1:

OldBulkReportFileName = Application._
GetOpenFilename("(*bulk*.xls), *bulk*.xls")

€˜change the name of the file
If OldBulkReportFileName < False Then
Name OldBulkReportFileName As BulkReportPath _
& BulkReportFileName

Else
MsgBox "Click OK and select the misnamed Bulk _
Report.", vbInformation, "You did not select a workbook."

GoTo Line1:

End If
End If

Region2:

€˜this is the Path the file should be in for Region2
BulkReportPath = "\\fileserver\Data\Global\Taskorder_
Documents\000\" & Region2BulkPrefix & "\" & Region2BulkID & "\"

€˜check to see if the Bulk Report is named correctly
If dir(BulkReportPath & BulkReportFileName) = "" Then

MsgBox "The Bulk Report is misnamed" & vbNewLine & _
vbNewLine & "Double click the Bulk Report in the" & _
vbNewLine & "next window and it will be renamed", _
vbInformation, "The Bulk Report is misnamed"

Line2:

OldBulkReportFileName = Application._
GetOpenFilename("(*bulk*.xls), *bulk*.xls")

€˜change the name of the file
If OldBulkReportFileName < False Then
Name OldBulkReportFileName As BulkReportPath _
& BulkReportFileName

Else
MsgBox "Click OK and select the misnamed Bulk _
Report.", vbInformation, "You did not select a workbook."

GoTo Line2:

End If
End If

As you can see, this is nearly identical from Region2 and will be for all
nine regions once this works. The problem is that when I execute the
Application.GetOpenFilename line the folder that gets opened is not the
folder with the incorrectly named file. I don't want the user to have to
search for this folder, I want the macro to open it.

Does anyone 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
How to set GetOpenFilename to a specific Folder Corey Excel Programming 4 July 31st 07 12:56 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven[_2_] Excel Programming 1 January 24th 06 04:23 AM
Application.GetOpenFilename vs Application.Dialogs(xlDialogsOpen) Paul Martin Excel Programming 5 August 5th 05 04:44 PM
GetOpenFilename - Default Folder Andy Excel Programming 3 September 19th 03 04:20 PM


All times are GMT +1. The time now is 10:08 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"