Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Userform Local Drive & Network drive question

I have a userform with two command buttons assigned to the following macros.
The user should be able to run the appropriate macro depending on the
location of a file, either on the local drive "C:\" or the Network drive.
After changing the current drive and running the macro a second time the
drive remains the one previously selected. Could someone please revise this
code to select the location of the Lotus File?


Sub ExportLocal()
CurDrive = "C:\"
ChDir "C:\P3WIN\PROJECTS"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files (*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub
Sub ExportNetwork()
CurDrive = "\\Bayltdest\Common2\Planning"
ChDir "\Shared Projects"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files (*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Userform Local Drive & Network drive question

Your code is pretty much the same thing for each option.

Maybe you could just have a single button that asks what folder should be used:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub
Sub ExportEither()
Dim Resp As Long
Dim NetworkPath As String
Dim LocalPath As String
Dim MyFile As Variant
Dim CurDriveFolder As String

NetworkPath = "\\Bayltdest\Common2\Planning\Shared Projects"
LocalPath = "C:\P3WIN\PROJECTS"

CurDriveFolder = CurDir

Resp = MsgBox(prompt:="Hit Yes for Local" _
& vbLf & "No for Network" & vbLf & "Or Cancel", _
Buttons:=vbYesNoCancel)

On Error Resume Next
If Resp = vbCancel Then
Exit Sub
ElseIf Resp = vbYes Then
ChDirNet LocalPath
Else
ChDirNet NetworkPath
End If
If Err.Number < 0 Then
MsgBox "error changing folder"
Err.Clear
Else
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files,*.wk?")
If MyFile = False Then
'do nothing
Else
Workbooks.Open MyFile
End If

ChDirNet CurDriveFolder
End If

End Sub

The ChDirNet is an API function that works when you change to a network
path/folder. But it works with local drives, too.




Joel Mills wrote:

I have a userform with two command buttons assigned to the following macros.
The user should be able to run the appropriate macro depending on the
location of a file, either on the local drive "C:\" or the Network drive.
After changing the current drive and running the macro a second time the
drive remains the one previously selected. Could someone please revise this
code to select the location of the Lotus File?

Sub ExportLocal()
CurDrive = "C:\"
ChDir "C:\P3WIN\PROJECTS"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files (*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub
Sub ExportNetwork()
CurDrive = "\\Bayltdest\Common2\Planning"
ChDir "\Shared Projects"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files (*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Userform Local Drive & Network drive question

'HOW TO CHANGE DRIVE AND FOLDER AS DEFAULT WHEN
' OPENING FILES WITH GETOPENFILENAME AS WELL AS
' HOW TO MAKE A UNC A DEFAULT BECAUSE CHDIR AND CHDRIVE
' DO NOT WORK WITH UNC PATHS.


'Public Sub OpenFile()
' Dim ProperPath As String
' Dim fName As Variant
' Dim wkbk As Workbook
'
' 'Save the current folder path
' ProperPath = CurDir
'
' 'Change the folder path
' ChDrive "C"
' ChDir "C:\My Path\My Folder"
'
' 'Display the open dialog box
' fName = Application.GetOpenFilename(fileFilter:="Excel Files
(*.xls),*.xls")
'
' Set wkbk = Workbooks.Open(fName)
'
' 'Change the default folder
' ChDrive ProperPath
' ChDir ProperPath
'
' Set wkbk = Nothing
'End Sub




'The 'ChDrive' and 'ChDir' functions don't understand UNC paths. There's a
very simple
'windows API function, however, that will set the current directory to a UNC
'path.
'
'Private Declare Function SetCurrentDirectoryA Lib "kernel32" (ByVal
'lpPathName As String) As Long
'
'Sub SetUNCPath()
' Dim lRet As Long
' lRet = SetCurrentDirectoryA("\\SERVER1\Downloads\")
' If lRet = 0 Then Err.Raise 9999, , "Error setting path."
'End Sub
'
'--
'Rob Bovey, MCSE
'The Payne Consulting Group



"Joel Mills" wrote:

I have a userform with two command buttons assigned to the following macros.
The user should be able to run the appropriate macro depending on the
location of a file, either on the local drive "C:\" or the Network drive.
After changing the current drive and running the macro a second time the
drive remains the one previously selected. Could someone please revise this
code to select the location of the Lotus File?


Sub ExportLocal()
CurDrive = "C:\"
ChDir "C:\P3WIN\PROJECTS"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files (*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub
Sub ExportNetwork()
CurDrive = "\\Bayltdest\Common2\Planning"
ChDir "\Shared Projects"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files (*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Userform Local Drive & Network drive question

Dave,thanks for the help. I thought a userform would be the right approach,
but this is a much cleaner soliton.

"Dave Peterson" wrote in message
...
Your code is pretty much the same thing for each option.
Dave,thanks for the help. I thought a userform would be the right

approach, but this is a much cleaner soliton.
Maybe you could just have a single button that asks what folder should be

used:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub
Sub ExportEither()
Dim Resp As Long
Dim NetworkPath As String
Dim LocalPath As String
Dim MyFile As Variant
Dim CurDriveFolder As String

NetworkPath = "\\Bayltdest\Common2\Planning\Shared Projects"
LocalPath = "C:\P3WIN\PROJECTS"

CurDriveFolder = CurDir

Resp = MsgBox(prompt:="Hit Yes for Local" _
& vbLf & "No for Network" & vbLf & "Or Cancel", _
Buttons:=vbYesNoCancel)

On Error Resume Next
If Resp = vbCancel Then
Exit Sub
ElseIf Resp = vbYes Then
ChDirNet LocalPath
Else
ChDirNet NetworkPath
End If
If Err.Number < 0 Then
MsgBox "error changing folder"
Err.Clear
Else
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files,*.wk?")
If MyFile = False Then
'do nothing
Else
Workbooks.Open MyFile
End If

ChDirNet CurDriveFolder
End If

End Sub

The ChDirNet is an API function that works when you change to a network
path/folder. But it works with local drives, too.




Joel Mills wrote:

I have a userform with two command buttons assigned to the following

macros.
The user should be able to run the appropriate macro depending on the
location of a file, either on the local drive "C:\" or the Network

drive.
After changing the current drive and running the macro a second time

the
drive remains the one previously selected. Could someone please revise

this
code to select the location of the Lotus File?

Sub ExportLocal()
CurDrive = "C:\"
ChDir "C:\P3WIN\PROJECTS"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files

(*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub
Sub ExportNetwork()
CurDrive = "\\Bayltdest\Common2\Planning"
ChDir "\Shared Projects"
Dim MyFile As String
MyFile = Application.GetOpenFilename("Lotus 1-2-3 Files

(*.wk?),*.wk?")
'Stop here if all you want is the path and file name - it's in the
'MyFile variable. 'Continue if you want to open it.
If MyFile = False Then End
Workbooks.Open (MyFile)
End Sub


--

Dave Peterson



Reply
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
Links to Local Drive Instead of Same Folder TKS_Mark Excel Discussion (Misc queries) 1 May 21st 09 06:07 AM
Excel in macro and connecting to a network drive question Mike S. Excel Discussion (Misc queries) 3 November 8th 08 02:51 AM
Links to mapped drive change to refer to local hard drive SueD Links and Linking in Excel 1 May 8th 08 11:42 AM
Link workbooks-C drive to network drive Earl Excel Worksheet Functions 0 April 19th 05 05:50 PM
Test whether current drive is local or remote? keepitcool Excel Programming 0 September 2nd 03 10:54 AM


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