Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default save file via Marco

Hi,

I'm using this macro :

Dim vFilename
vFilename = "Export Q 1.0 " & Worksheets
("Export").Range("A2").Value & ".xls"
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:=vFilename,
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close

The problem is that the file is not allways saved on c:

Is it possible to save it allways on C:
Or is it even possible to save in on C:\XXX.
Can be checked If c:\XXX exists ? If not create C:\XXX ?

Thanks !
Tom
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default save file via Marco

Tom,

Here is one way

Sub CheckFolder()
Dim vFilename
Dim sFolder
Dim fso
sFolder = "C:\NewDir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If
vFilename = sFolder & "\" & _
"Export Q 1.0 " & _
Worksheets("Export").Range("A2").Value & ".xls"
ActiveWorkbook.SaveAs Filename:=vFilename, _
FileFormat:= _
xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWindow.Close
End Sub

'-----------------------------------------------------------------
Function FolderExists(Folder) As Boolean
'-----------------------------------------------------------------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
FolderExists = True
End If
End If
End Function




--

HTH

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

"Tom" wrote in message
...
Hi,

I'm using this macro :

Dim vFilename
vFilename = "Export Q 1.0 " & Worksheets
("Export").Range("A2").Value & ".xls"
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:=vFilename,
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close

The problem is that the file is not allways saved on c:

Is it possible to save it allways on C:
Or is it even possible to save in on C:\XXX.
Can be checked If c:\XXX exists ? If not create C:\XXX ?

Thanks !
Tom



  #3   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default save file via Marco

Bob,

I understand the first part.
Does the first part works if the folfer allready exists ?

I don't understand the second part
sFolder = Dir(Folder, vbDirectory) is here Folder the
name of the folfer ?

What does it do ?
Has it to be run before the first part ?
PS : I don't know if the folder allready exists on the
PC's that are using this XLS file and so this marco ...
So it has to work wether it exists or not.

Thanks !
Tom


-----Original Message-----
Tom,

Here is one way

Sub CheckFolder()
Dim vFilename
Dim sFolder
Dim fso
sFolder = "C:\NewDir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If
vFilename = sFolder & "\" & _
"Export Q 1.0 " & _
Worksheets("Export").Range("A2").Value

& ".xls"
ActiveWorkbook.SaveAs Filename:=vFilename, _
FileFormat:= _
xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWindow.Close
End Sub

'--------------------------------------------------------

---------
Function FolderExists(Folder) As Boolean
'--------------------------------------------------------

---------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) =

vbDirectory Then
FolderExists = True
End If
End If
End Function




--

HTH

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

"Tom" wrote in

message
...
Hi,

I'm using this macro :

Dim vFilename
vFilename = "Export Q 1.0 " & Worksheets
("Export").Range("A2").Value & ".xls"
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:=vFilename,
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close

The problem is that the file is not allways saved on c:

Is it possible to save it allways on C:
Or is it even possible to save in on C:\XXX.
Can be checked If c:\XXX exists ? If not create

C:\XXX ?

Thanks !
Tom



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default save file via Marco

I tested this :
Dim sFolder
Dim fso
sFolder = "C:\ABC"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If
End Sub

But it doesn't work
FolderExists : Sub or function not defined

Tom

-----Original Message-----
Bob,

I understand the first part.
Does the first part works if the folfer allready exists ?

I don't understand the second part
sFolder = Dir(Folder, vbDirectory) is here Folder the
name of the folfer ?

What does it do ?
Has it to be run before the first part ?
PS : I don't know if the folder allready exists on the
PC's that are using this XLS file and so this marco ...
So it has to work wether it exists or not.

Thanks !
Tom


-----Original Message-----
Tom,

Here is one way

Sub CheckFolder()
Dim vFilename
Dim sFolder
Dim fso
sFolder = "C:\NewDir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If
vFilename = sFolder & "\" & _
"Export Q 1.0 " & _
Worksheets("Export").Range("A2").Value

& ".xls"
ActiveWorkbook.SaveAs Filename:=vFilename, _
FileFormat:= _
xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWindow.Close
End Sub

'-------------------------------------------------------

-
---------
Function FolderExists(Folder) As Boolean
'-------------------------------------------------------

-
---------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) =

vbDirectory Then
FolderExists = True
End If
End If
End Function




--

HTH

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

direct)

"Tom" wrote in

message
...
Hi,

I'm using this macro :

Dim vFilename
vFilename = "Export Q 1.0 " & Worksheets
("Export").Range("A2").Value & ".xls"
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:=vFilename,
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close

The problem is that the file is not allways saved on

c:

Is it possible to save it allways on C:
Or is it even possible to save in on C:\XXX.
Can be checked If c:\XXX exists ? If not create

C:\XXX ?

Thanks !
Tom



.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default save file via Marco

Tom,

You have to add both bits of code to your workbook, as the first uses the
second.

If the folder exists it works fine, using that folder. If it doesn't it
creates it.

--

HTH

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

"Tom" wrote in message
...
Bob,

I understand the first part.
Does the first part works if the folfer allready exists ?

I don't understand the second part
sFolder = Dir(Folder, vbDirectory) is here Folder the
name of the folfer ?

What does it do ?
Has it to be run before the first part ?
PS : I don't know if the folder allready exists on the
PC's that are using this XLS file and so this marco ...
So it has to work wether it exists or not.

Thanks !
Tom


-----Original Message-----
Tom,

Here is one way

Sub CheckFolder()
Dim vFilename
Dim sFolder
Dim fso
sFolder = "C:\NewDir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If
vFilename = sFolder & "\" & _
"Export Q 1.0 " & _
Worksheets("Export").Range("A2").Value

& ".xls"
ActiveWorkbook.SaveAs Filename:=vFilename, _
FileFormat:= _
xlNormal, Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWindow.Close
End Sub

'--------------------------------------------------------

---------
Function FolderExists(Folder) As Boolean
'--------------------------------------------------------

---------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) =

vbDirectory Then
FolderExists = True
End If
End If
End Function




--

HTH

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

"Tom" wrote in

message
...
Hi,

I'm using this macro :

Dim vFilename
vFilename = "Export Q 1.0 " & Worksheets
("Export").Range("A2").Value & ".xls"
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:=vFilename,
FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close

The problem is that the file is not allways saved on c:

Is it possible to save it allways on C:
Or is it even possible to save in on C:\XXX.
Can be checked If c:\XXX exists ? If not create

C:\XXX ?

Thanks !
Tom



.





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
run marco to send a excel file by email(lotus note) Wu Excel Discussion (Misc queries) 1 December 12th 09 05:42 AM
Marco To Save Column A7 As A .txt File. Chris Excel Worksheet Functions 11 May 30th 08 10:20 AM
when i save xls file, debug script is running and canno't save fil Imtiaz Excel Discussion (Misc queries) 1 July 16th 05 03:47 PM
Excell2003 (SP-1) File > Save and File > Save As.. grayed out Joe Murphy Excel Discussion (Misc queries) 0 March 9th 05 10:00 PM
Save File to Another Directory, but not change Users File Save location Mike Knight Excel Programming 1 May 28th 04 09:06 PM


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