Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-23-2014, 12:42 PM
landonminden landonminden is offline VBA FileCopy Source: problem Windows 7 64bit VBA FileCopy Source: problem Office 2010 64bit
Novice
VBA FileCopy Source: problem
 
Join Date: Sep 2014
Posts: 2
landonminden is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 09-23-2014, 11:11 PM
gmayor's Avatar
gmayor gmayor is offline VBA FileCopy Source: problem Windows 7 64bit VBA FileCopy Source: problem Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 09-24-2014, 08:00 AM
landonminden landonminden is offline VBA FileCopy Source: problem Windows 7 64bit VBA FileCopy Source: problem Office 2010 64bit
Novice
VBA FileCopy Source: problem
 
Join Date: Sep 2014
Posts: 2
landonminden is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 12-16-2015, 12:58 AM
gazeranco gazeranco is offline VBA FileCopy Source: problem Windows 7 64bit VBA FileCopy Source: problem Office 2010 64bit
Novice
 
Join Date: Dec 2015
Posts: 5
gazeranco is on a distinguished road
Question 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
Reply With Quote
  #5  
Old 12-16-2015, 01:02 AM
gazeranco gazeranco is offline VBA FileCopy Source: problem Windows 7 64bit VBA FileCopy Source: problem Office 2010 64bit
Novice
 
Join Date: Dec 2015
Posts: 5
gazeranco is on a distinguished road
Default

oops... this was supposed to be a thread not a reply, how did I do that :s
Reply With Quote
Reply

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
VBA FileCopy Source: problem 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
VBA FileCopy Source: problem editing source formatting urboyfriend Word 1 09-22-2011 02:43 AM
Installation Source Corrupted browneyes Office 1 01-23-2006 02:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft