Copy template to user’s pc
I told you guys i will come everyday ! :wave:
Small problem .. i thought i would ask before looking for a solution .. lets see who is faster :D
Template is somewhere on a server .. it’s a small PC not really a server …
What i need is an automation where it controls if the template is not copyed to a user pc’s it will copy it for him/her with specific path like c:\somewhere\indTemplate… , I need that kind of system is cos most of the users have laptops and they don’t work on network , every now and then they log in to upload there files and data .. that is all ...
Re: Copy template to user’s pc
Here's a procedure I use to download a template. You will need to tweak the constants, but it should get you started...
VB Code:
Option Explicit
' Filename constants.
Public Const gsFILE_DPS_PRICING_MODEL As String = "DPS_Pricing_Model.xlt"
Public Const gsAPP_DIRECTORY As String = "C:\Pricing_Model\"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Comments: This procedure downloads a new copy of the
' Pricing Model template.
'
' Arguments: None
'
' Date Developer Action
' --------------------------------------------------------------
' 01/13/06 Declan Kenny Initial version
Public Sub DownLoadTemplate()
Const sDOWNLOAD_DRIVE As String = "your network address"
Dim wkbTemplate As Workbook
Set wkbTemplate = Workbooks.Open(Filename:=sDOWNLOAD_DRIVE & gsFILE_DPS_PRICING_MODEL)
wkbTemplate.SaveAs Filename:=gsAPP_DIRECTORY & gsFILE_DPS_PRICING_MODEL, _
FileFormat:=xlTemplate
wkbTemplate.Close False
Set wkbTemplate = Nothing
End Sub
Re: Copy template to user’s pc
hi D.
Thx for the reply .. i will say it who know i might need it one day ,
I was busy today with the template , I realised I was wrong with what I need.
I made a template for Adobe Indsign the point of the template that users will only use specific paragraph styles in WORD so when they import them in it will matches the styles automatically , it work perfectly in a way that made me made 5 different kind of templates
But what I need now is like a system to let my users update the last edit templates every now and then
What I do now is make a WORD template put it in the same Dir for the ind. Template all the components that belong to that template that is how it will be easier for my users to get every thing in one directory
Your update system is is perfect , but I would love now to let my users , when they start that word template it should copy the full ind Dir & files in it from the server to there local station like that :
Copy from:
G:\IND templates\A4
Paste in :
C:\Projacts doc\A4
Your think its possible ??
I made a small function for word files , but for a DIR
PS: am not a programmer but I can find my way around :p
Re: Copy template to user’s pc
Sure its possible...
Here's a procedure that take a source path and a destination path and then copies all files from the source to the destination.
The testit sub hows how you would use this procedure.
VB Code:
Sub testit()
String_O_FileCopy "C:\data\testsource\", "C:\data\testdestination\"
End Sub
Sub String_O_FileCopy(SourceDir As String, DestinationDir As String)
Dim sFileName As String
Dim sSource As String
Dim sDestination As String
'Make sure the paths end with a slash
If Right(SourceDir, 1) <> "\" Then SourceDir = SourceDir & "\"
If Right(DestinationDir, 1) <> "\" Then DestinationDir = DestinationDir & "\"
'Get the first file name
'in the Source
sFileName = Dir(SourceDir)
'Loop through all files
Do While sFileName <> ""
'Fully qualified source path
sSource = SourceDir & sFileName
'Fully qualified destination path
sDestination = DestinationDir & sFileName
'Copy the file to the new location
FileCopy sSource, sDestination
'Move to the next file
sFileName = Dir
Loop
End Sub
Re: Copy template to user’s pc
it worked perfectly but .. it copy only files
but what if some ppl. didn’t make the dir .. they just run the script ? i tried something like that
If FolderExists("c:\MyFolder") = True Then
'dont make folder just copy files
Else
'make Dir and
and copy Files Folder
End If
Re: Copy template to user’s pc
String-O
Can you post the code for what you tried?
You should be using a MkDir statement to create the directory.
Re: Copy template to user’s pc
this is what i was busy with
VB Code:
Sub getINDcomp
Dim DirIND As New FileSystemObject
If DirIND .DriveExists("c:\INDFOLDER") = True Then
'just copy
Else
MsgBox "Boy are you in big trouble!"
DirIND .CreateFolder "c:\INDFOLDER"
' and copy Files
End If
end sub
Re: Copy template to user’s pc
You are all most there. Rather than using the DriveExists method you should be using the FolderExists method. The easiest thing to do here is check to see if the folder exists and if it soesn't - then create it. After that you can continue with the code as above.
VB Code:
Sub String_O_FileCopy(SourceDir As String, DestinationDir As String)
Dim oDirIND As Scripting.FileSystemObject
Dim sFileName As String
Dim sSource As String
Dim sDestination As String
'Make sure the paths end with a slash
If Right(SourceDir, 1) <> "\" Then SourceDir = SourceDir & "\"
If Right(DestinationDir, 1) <> "\" Then DestinationDir = DestinationDir & "\"
Set oDirIND = New Scripting.FileSystemObject
'If the destination folder doesn't exit then
'create it
If Not oDirIND.FolderExists(DestinationDir) Then
oDirIND.CreateFolder DestinationDir
End If
Set oDirIND = Nothing
'Get the first file name
'in the Source
sFileName = Dir(SourceDir)
'Loop through all files
Do While sFileName <> ""
'Fully qualified source path
sSource = SourceDir & sFileName
'Fully qualified destination path
sDestination = DestinationDir & sFileName
'Copy the file to the new location
FileCopy sSource, sDestination
'Move to the next file
sFileName = Dir
Loop
End Sub
Re: Copy template to user’s pc
Do u mean with SourceDir like that ...
and would work if i add it on AutoOpen ?
If Right(SourceDir, 1) <> "\" Then SourceDir = C:\MynewDir& "\"
If Right(DestinationDir, 1) <> "\" Then DestinationDir = G:\Orginaldir& "\"