#1
|
|||
|
|||
VBA FileCopy Source: problem
I am trying to copy a template (Normal.dotm) from a server to desktop template folder using VBA.
The file I want to copy has xml (custom tabs) however when I run the code it copies the file but it doesnt bring the xml with the file. If I physically copy the file it works fine and the tabs are there when I open it. Here is the code I have copying the file to my roaming folder: Sub copyfile() ' MsgBox VBA.Environ("username") Dim UserName As String UserName = VBA.Environ("username") Options.DefaultFilePath(Path:=wdUserTemplatesPath) = "C:\users\" & UserName & "\appdata\roaming\Microsoft\Templates" FileCopy Source:="\\ggnnd\GROUP\PLNG\Normal.dotm", Destination:="C:\users\" & UserName & "\appdata\roaming\Microsoft\Templates\Normal.d otm" End Sub Do I need a macro to copy the xml somehow I couldnt find anything on the internet. Any Help would be much appreciated. |
#2
|
||||
|
||||
The issue appears to be that you are running a macro from Word that will copy a normal template to Word which already has the normal template open. You cannot overwrite a file that is in use - and you certainly cannot run a macro from the normal template that, even if was possible, would replace itself.
The way to do this would be from a log-in script before Word is started, though frankly I would question the wisdom of it (other than for initial setup). The normal template is a personal user file. This type of over-arching central control, ruins productivity from your better Word users, and is completely unnecessary. If you need particular conditions for documents then give the users document templates from which to create their company documents. If you simply want to supply a set of macros, then supply them in the form of an add-in template - and again that would have to be copied using a log-in script.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thanks for the reply,
I ended up just making a .bat file to install and overwrite the users normal.dotm file. I know it is not typically a good practice to overwrite the end users normal file but I know that none of them have a custom ribbon. No one in my department knows what a macro is so in my case this was the easiest fix. |
#4
|
|||
|
|||
Roaming Template Folder Help
Hey All,
New here so welcome to me, and thanks for having me! I did a quick search to no avail. I use some CAD software and it produces lists for me in .xsr format, not really sure what that is but once done I open them with word, fix the formatting and then save as a .doc. I recorded a macro to do this for me automatically, but the first issue I had was it was calling everyfile the same name. So I setup a variable/method to get the current file name, but it always uses the same name and its not the corrrect name. It always saves the file as "templates.doc" in "C:\users\me\AppData\Roaming\Microsoft\Templates\T emplates.doc" instead of where the file really is (on my desktop in a folder) and its real name (not template) Any ideas? Code below! Code:
Sub Format() ' ' Format Macro ' Report Format ' Dim fso As New FileSystemObject myPath = ThisDocument.Path myName = fso.GetBaseName(myPath) With Selection.PageSetup .LineNumbering.Active = False .Orientation = wdOrientPortrait .TopMargin = CentimetersToPoints(1.27) .BottomMargin = CentimetersToPoints(1.27) .LeftMargin = CentimetersToPoints(1.27) .RightMargin = CentimetersToPoints(1.27) .Gutter = CentimetersToPoints(0) .HeaderDistance = CentimetersToPoints(1.25) .FooterDistance = CentimetersToPoints(1.25) .PageWidth = CentimetersToPoints(21) .PageHeight = CentimetersToPoints(29.7) .FirstPageTray = wdPrinterDefaultBin .OtherPagesTray = wdPrinterDefaultBin .SectionStart = wdSectionNewPage .OddAndEvenPagesHeaderFooter = False .DifferentFirstPageHeaderFooter = False .VerticalAlignment = wdAlignVerticalTop .SuppressEndnotes = False .MirrorMargins = False .TwoPagesOnOne = False .BookFoldPrinting = False .BookFoldRevPrinting = False .BookFoldPrintingSheets = 1 .GutterPos = wdGutterPosLeft End With Selection.WholeStory Selection.Font.Size = 10 Selection.Font.Name = "Courier New" ChangeFileOpenDirectory (myPath) ActiveDocument.SaveAs2 fileName:=(myName), FileFormat:= _ wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _ True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _ False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False, CompatibilityMode:=0 End Sub |
#5
|
|||
|
|||
oops... this was supposed to be a thread not a reply, how did I do that :s
|
Tags |
filecopy, vba, xml |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cannot open the source object | Satish1985 | Excel | 0 | 02-06-2014 08:32 PM |
Create DDL from Excel source | BradleyS | Word | 1 | 01-30-2013 10:58 PM |
Cannot find source of overallocation | nesskramer | Project | 3 | 06-29-2012 08:46 AM |
editing source formatting | urboyfriend | Word | 1 | 09-22-2011 02:43 AM |
Installation Source Corrupted | browneyes | Office | 1 | 01-23-2006 02:33 PM |