Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Prompt for new folder

Recording a macro, I am trying to get the prompt to create a new folder. It
will only record properly if I enter a folder name, but I would like it to
wait until I give it a new folder name. What is the correct code for this?

Phil


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Prompt for new folder


Do
ans = your_prompt_code
Loop Until ans < ""

you may have to test for False depending upon your prompt code

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Phil Floyd" wrote in message
...
Recording a macro, I am trying to get the prompt to create a new folder.

It
will only record properly if I enter a folder name, but I would like it to
wait until I give it a new folder name. What is the correct code for

this?

Phil




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Prompt for new folder

Bob, I don't have any prompt code. I am trying to get the dialogue box that
you use to give a folder a name to show. It is the one labeled "Create New
Folder" and is accessed from the "Open" dialogue box.

Phil

"Bob Phillips" wrote in message
...

Do
ans = your_prompt_code
Loop Until ans < ""

you may have to test for False depending upon your prompt code

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Phil Floyd" wrote in message
...
Recording a macro, I am trying to get the prompt to create a new folder.

It
will only record properly if I enter a folder name, but I would like it

to
wait until I give it a new folder name. What is the correct code for

this?

Phil






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Prompt for new folder

Phil,

Assuming you really mean a folder and not a file, this code will do it

This code below will run a folder browse dialog and return the selected
folder

This is a demo of how to use it

Dim ans

Do
ans = GetFolder
Loop Until ans < ""

MsgBox ans

You can use the returned value to set the directory before saving.e.g

myDir = GetFolder
ChDrive myDir
CurDir myDir



'==============================
'Code starts here

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Phil Floyd" wrote in message
...
Bob, I don't have any prompt code. I am trying to get the dialogue box

that
you use to give a folder a name to show. It is the one labeled "Create

New
Folder" and is accessed from the "Open" dialogue box.

Phil

"Bob Phillips" wrote in message
...

Do
ans = your_prompt_code
Loop Until ans < ""

you may have to test for False depending upon your prompt code

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Phil Floyd" wrote in message
...
Recording a macro, I am trying to get the prompt to create a new

folder.
It
will only record properly if I enter a folder name, but I would like

it
to
wait until I give it a new folder name. What is the correct code for

this?

Phil








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Prompt for new folder

Thanks Bob. This gets me started.

Phil

"Bob Phillips" wrote in message
...
Phil,

Assuming you really mean a folder and not a file, this code will do it

This code below will run a folder browse dialog and return the selected
folder

This is a demo of how to use it

Dim ans

Do
ans = GetFolder
Loop Until ans < ""

MsgBox ans

You can use the returned value to set the directory before saving.e.g

myDir = GetFolder
ChDrive myDir
CurDir myDir



'==============================
'Code starts here

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Phil Floyd" wrote in message
...
Bob, I don't have any prompt code. I am trying to get the dialogue box

that
you use to give a folder a name to show. It is the one labeled "Create

New
Folder" and is accessed from the "Open" dialogue box.

Phil

"Bob Phillips" wrote in message
...

Do
ans = your_prompt_code
Loop Until ans < ""

you may have to test for False depending upon your prompt code

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Phil Floyd" wrote in message
...
Recording a macro, I am trying to get the prompt to create a new

folder.
It
will only record properly if I enter a folder name, but I would like

it
to
wait until I give it a new folder name. What is the correct code

for
this?

Phil










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
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
how can i change my default working folder to a networked folder? wizard1154 Excel Discussion (Misc queries) 4 April 18th 07 07:29 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
save prompt for user exit, but no save prompt for batch import? lpj Excel Discussion (Misc queries) 1 February 25th 06 02:08 AM
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


All times are GMT +1. The time now is 12:29 AM.

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

About Us

"It's about Microsoft Excel"