View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Robert ap Rhys Robert ap Rhys is offline
external usenet poster
 
Posts: 21
Default Save files to generalized location?


"rach85" wrote in
message ...


Yep, that's pretty much it. Then you can write a nice little function to
call it:

Option Explicit

Private Declare Function GetTempPathA Lib "kernel32" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Function GetTempPath() As String
Dim lpBuffer As String
Dim nBufferLength As Long
Dim Ret As Long

nBufferLength = 255
lpBuffer = Space$(nBufferLength)
Ret = GetTempPathA(nBufferLength, lpBuffer)
GetTempPath = Left$(lpBuffer, Ret)
End Function

Function SaveWorkbook(Name As String, Workbook As Workbook, _
Optional MakeCopy As Boolean = False) As String

Dim strPath As String
' Get path to temp folder
strPath = GetTempPath
' Make sure we have a trailing slash..
If Not Right(strPath, 1) = Application.PathSeparator Then _
strPath = strPath & Application.PathSeparator
' Build full filename
strPath = strPath & Name

' Save workbook or a copy?
If MakeCopy Then
' Just a copy
Workbook.SaveCopyAs strPath
Else
' The workbook itself
Workbook.SaveAs strPath
End If

' Rturn path to the saved workbook...
SaveWorkbook = strPath

End Function


And call /that/ function like this (for example):

Sub Test()
MsgBox SaveWorkbook("test.xls", ThisWorkbook, True) _
& " Saved.", vbInformation
End Sub


HTH

Robert