Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Make new folder & save to it


Hi, I was wondering if anybody knows a way, through VBA, to create a new
folder in the same directory and then save the active workbook to that
new folder?

Thanks in advance


--
krabople
------------------------------------------------------------------------
krabople's Profile: http://www.excelforum.com/member.php...o&userid=29774
View this thread: http://www.excelforum.com/showthread...hreadid=504845

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Make new folder & save to it

Dear Krabople:

Here are a couple of routines that may help. Modofy as necessary.

Sub MakeFolderAndSaveActiveBook()
Dim foldername As String
Dim filename As String
Dim s As String
Dim wb As Workbook
foldername = "ggg" ' modify for folder name
filename = "filename.xls"
s = CreateFolder(foldername)
If Len(s) 0 Then
MsgBox s, vbOKOnly, "Created"
s = s & "\" & filename
ActiveWorkbook.SaveAs s
MsgBox s, vbOKOnly, "Created"
Else
MsgBox "Cannot Create Folder " & foldername, vbOKOnly, "Cannot
create folder"
End If
End Sub

Function CreateFolder(folder As String) As String
Dim p As Variant
On Error GoTo Err
CreateFolder = ""
p = CurDir
If Len(p) 0 Then
If Right(p, 1) < "\" Then p = p & "\"
p = p & folder
MkDir p
CreateFolder = p
End If
Err:
End Function

--
HTHs Martin


"krabople" wrote:


Hi, I was wondering if anybody knows a way, through VBA, to create a new
folder in the same directory and then save the active workbook to that
new folder?

Thanks in advance


--
krabople
------------------------------------------------------------------------
krabople's Profile: http://www.excelforum.com/member.php...o&userid=29774
View this thread: http://www.excelforum.com/showthread...hreadid=504845


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Make new folder & save to it


That's perfect, thanks very much for your help!


--
krabople
------------------------------------------------------------------------
krabople's Profile: http://www.excelforum.com/member.php...o&userid=29774
View this thread: http://www.excelforum.com/showthread...hreadid=504845

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Make new folder & save to it


Hi, thanks again for the code, it works great. The only problem is that
it creates the folder in My Documents for some reason whereas I need
the folder to be in the same directory as the active workbook. How do I
do this?


--
krabople
------------------------------------------------------------------------
krabople's Profile: http://www.excelforum.com/member.php...o&userid=29774
View this thread: http://www.excelforum.com/showthread...hreadid=504845

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Make new folder & save to it

Try this:

Function CreateFolder(folder As String) As String
Dim p As Variant
On Error GoTo Err
CreateFolder = ""
p = ActiveWorkbook.Path ' CurDir of active workbook<<<<<<<<<<<<
If Len(p) 0 Then
If Right(p, 1) < "\" Then p = p & "\"
p = p & folder
MkDir p
CreateFolder = p
End If
Err:
End Function


--
HTHs Martin


"krabople" wrote:


Hi, thanks again for the code, it works great. The only problem is that
it creates the folder in My Documents for some reason whereas I need
the folder to be in the same directory as the active workbook. How do I
do this?


--
krabople
------------------------------------------------------------------------
krabople's Profile: http://www.excelforum.com/member.php...o&userid=29774
View this thread: http://www.excelforum.com/showthread...hreadid=504845




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Make new folder & save to it


Brilliant that's done the job, thanks again


--
krabople
------------------------------------------------------------------------
krabople's Profile: http://www.excelforum.com/member.php...o&userid=29774
View this thread: http://www.excelforum.com/showthread...hreadid=504845

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
How I can make a passward on the folder? Malik New Users to Excel 2 August 22nd 06 05:56 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
open file from folder save in new folder tim64[_3_] Excel Programming 20 June 17th 05 07:58 PM
"Save As" folder -- can I default this to the same folder as origi Mike Excel Discussion (Misc queries) 1 June 11th 05 12:06 AM
Using VBA in Excel to Make a Folder to Save Workbooks in Jeff Marshall[_2_] Excel Programming 2 September 22nd 03 08:36 PM


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