Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default SaveAs with a pre-defined filename

Hi All,

I'd like to save a workbook created from a template with a macro-generated
filename, not allowing the user to change the filename, but allowing to
select a path for the workbook. How can I do that?

TIA,
Stefi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default SaveAs with a pre-defined filename

Stefi,

Here is one way. XL2002 has a browse dialog. I don't use 2002 myself, so you
may need to play with this, but this is basically it

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is below. Just append the filename to the returned
folder.

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

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Hi All,

I'd like to save a workbook created from a template with a macro-generated
filename, not allowing the user to change the filename, but allowing to
select a path for the workbook. How can I do that?

TIA,
Stefi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default SaveAs with a pre-defined filename

Thanks, Bob, I forgot to mention that I use XL2000, but I will consider to
upgrade to 2002 or 2003, because the 2002 solution is so much simpler!

Regards,
Stefi


€žBob Phillips€ ezt Ã*rta:

Stefi,

Here is one way. XL2002 has a browse dialog. I don't use 2002 myself, so you
may need to play with this, but this is basically it

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is below. Just append the filename to the returned
folder.

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

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Hi All,

I'd like to save a workbook created from a template with a macro-generated
filename, not allowing the user to change the filename, but allowing to
select a path for the workbook. How can I do that?

TIA,
Stefi




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default SaveAs with a pre-defined filename

Hardly seems justification for spending that much to me :-))

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Thanks, Bob, I forgot to mention that I use XL2000, but I will consider to
upgrade to 2002 or 2003, because the 2002 solution is so much simpler!

Regards,
Stefi


"Bob Phillips" ezt írta:

Stefi,

Here is one way. XL2002 has a browse dialog. I don't use 2002 myself, so

you
may need to play with this, but this is basically it

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is below. Just append the filename to the returned
folder.

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

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Hi All,

I'd like to save a workbook created from a template with a

macro-generated
filename, not allowing the user to change the filename, but allowing

to
select a path for the workbook. How can I do that?

TIA,
Stefi






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default SaveAs with a pre-defined filename

Hi Bob,

I changed my mind, because I gave an early answer without testing your
solution. It thought it a difficult method but it worked at once just like I
wanted, although I can't follow it. How can one learn such things?

I appreciate very much your efforts!

Regards,
Stefi


€žBob Phillips€ ezt Ã*rta:

Hardly seems justification for spending that much to me :-))

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Thanks, Bob, I forgot to mention that I use XL2000, but I will consider to
upgrade to 2002 or 2003, because the 2002 solution is so much simpler!

Regards,
Stefi


"Bob Phillips" ezt Ã*rta:

Stefi,

Here is one way. XL2002 has a browse dialog. I don't use 2002 myself, so

you
may need to play with this, but this is basically it

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is below. Just append the filename to the returned
folder.

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

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Hi All,

I'd like to save a workbook created from a template with a

macro-generated
filename, not allowing the user to change the filename, but allowing

to
select a path for the workbook. How can I do that?

TIA,
Stefi









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default SaveAs with a pre-defined filename

Wise move, especially as Office 12 is coming out next year (ish), and that
will be worth upgrading to.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Hi Bob,

I changed my mind, because I gave an early answer without testing your
solution. It thought it a difficult method but it worked at once just like

I
wanted, although I can't follow it. How can one learn such things?

I appreciate very much your efforts!

Regards,
Stefi


"Bob Phillips" ezt írta:

Hardly seems justification for spending that much to me :-))

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Thanks, Bob, I forgot to mention that I use XL2000, but I will

consider to
upgrade to 2002 or 2003, because the 2002 solution is so much simpler!

Regards,
Stefi


"Bob Phillips" ezt írta:

Stefi,

Here is one way. XL2002 has a browse dialog. I don't use 2002

myself, so
you
may need to play with this, but this is basically it

With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)

End With

Look up FileDialog in the VBA help

The pre XL2002 way is below. Just append the filename to the

returned
folder.

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

RP
(remove nothere from the email address if mailing direct)


"Stefi" wrote in message
...
Hi All,

I'd like to save a workbook created from a template with a

macro-generated
filename, not allowing the user to change the filename, but

allowing
to
select a path for the workbook. How can I do that?

TIA,
Stefi









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
SaveAs Filename and FileFormat in Vs2007 RobN[_2_] Excel Discussion (Misc queries) 4 July 14th 07 01:21 AM
SaveAs using two cells for filename David Excel Discussion (Misc queries) 5 June 4th 05 11:46 AM
FileName SaveAs alanford Excel Programming 1 February 18th 05 01:01 PM
'ActiveWorkbook.SaveAs Filename' TOMB Excel Programming 2 February 15th 05 11:51 PM
SaveAs Filename Help Ed[_14_] Excel Programming 2 November 20th 03 07:43 PM


All times are GMT +1. The time now is 03:05 PM.

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"