Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
I have a macro that brings up an Input Box which takes a filename (fnames$) and saves an excel sheet as that filename, I need this to create a folder first then save itself in the folder. The folder name would be the same as strProjectNumber... bk.SaveAs FileName:="C:\LOA\" & strProjectNumber & "\" & fnames$ OK, well obviously the above doesn't work but I am trying to get it to save as C:\LOA\ = Then a new folder based on the strProjectName = Then the filename fnames$ (previously entered from an Input Box (No help needed with this)) Anyone help? -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Use mkdir "C:\LOA\" & strProjectNumber before you save the file. Co -- colofnatur ----------------------------------------------------------------------- colofnature's Profile: http://www.excelforum.com/member.php...fo&userid=3435 View this thread: http://www.excelforum.com/showthread.php?threadid=54552 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Thanks! But if the directory I am trying to make already exists will that be a problem? Also how would I then enter the save command to reflect the directory based on strProjectNumber. -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Yup, 'fraid so. It'll throw up a run-time error (75, if you're interested). You could either trap this error, or check for the existence of the directory before you attempt to create it. -- colofnature ------------------------------------------------------------------------ colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Hmm ok, I am an idiot and not very VB talented ;) the idea of checking first seems sensible, how wuold I do that though? -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Something like if dir("C:\LOA\" & strProjectNumber,vbdirectory)<"" then msgbox "Folder already exists!", vbcritical exit sub ' or whatever... endif -- colofnature ------------------------------------------------------------------------ colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Thanks, but if the directory exists I just want the files saved in it rather than it quitting out, and I still don't know how to modify the path when saving the file to reflect the directory name. I did warn you I was an idiot. :P -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
No worries! Your code needs to be if dir("C:\LOA\" & strProjectNumber,vbdirectory) = "" then mkdir "C:\LOA\" & strProjectNumber bk.SaveAs FileName:="C:\LOA\" & strProjectNumber & "\" & fnames$ Sorted! -- colofnature ------------------------------------------------------------------------ colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Sorted indeed! Thanks! :) -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Sorted indeed! Thanks! :) -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
Hi Chris,
on error resume next mkdir "C:\LOA\" & strProjectNumber 'if already exists you will get error err = 0 'you don't check for this error (either the folder was created or already exists. Third possibility is write protected disk - not worth to check, because also saving will fail) bk.SaveAs FileName:="C:\LOA\" & strProjectNumber & "\" & fnames$ if err<0 then msgbox "Error while saving" else msgbox "Saved" end if on error goto 0 Regards, Ivan |
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
On Error Resume Next
mkdir "C:\LOA\" & strProjectNumber On Error Goto 0 -- HTH Bob Phillips (replace somewhere in email address with googlemail if mailing direct) "colofnature" wrote in message ... No worries! Your code needs to be if dir("C:\LOA\" & strProjectNumber,vbdirectory) = "" then mkdir "C:\LOA\" & strProjectNumber bk.SaveAs FileName:="C:\LOA\" & strProjectNumber & "\" & fnames$ Sorted! -- colofnature ------------------------------------------------------------------------ colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
#13
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a folder using macro...
s$ = "C:\LOA\" & strProjectNumber
On Error Resume Next mkdir "C:\LOA\" & strProjectNumber On Error goto 0 bk.SaveAs FileName:= s$ & "\" & fnames$ should do what you want. -- Regards, Tom Ogilvy "ChrisMattock" wrote: Thanks, but if the directory exists I just want the files saved in it rather than it quitting out, and I still don't know how to modify the path when saving the file to reflect the directory name. I did warn you I was an idiot. :P -- ChrisMattock ------------------------------------------------------------------------ ChrisMattock's Profile: http://www.excelforum.com/member.php...o&userid=33912 View this thread: http://www.excelforum.com/showthread...hreadid=545527 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro creating folder and files automatically, without permission. | Excel Discussion (Misc queries) | |||
Creating a new folder | Excel Programming | |||
Creating Folder Folder in My Documents VBA - HELP | Excel Programming | |||
Macro for creating folder | Excel Programming | |||
creating folder | Excel Programming |