![]() |
|
|
|
#1
|
|||
|
|||
|
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
|
|
#2
|
||||
|
||||
|
'ThisDocument' is the document containing the macro - probably the normal template. What you are interested in here is the 'ActiveDocument'. The code you need is
Code:
Dim myName As String
myName = Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, Chr(46))) & "docx"
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Graham, works like a charm! Thank you.
Maybe you can help me solve another issue, currently I am using python to say... for each document in folder... open document... run macro.... Would you know another way of achieving this without python. Say a .bat or something? What I don't want to do is install python on everyone PC in the office who would also benefit from this 'auto' formatting of word docs. All I really know is Python so its my goto language. |
|
#4
|
|||
|
|||
|
Graham,
Actually I think I can do this in c# and add it to the software we use to produce the actual lists, that will be a clean solution which will work for everyone. Thanks for your help again! |
|
#5
|
||||
|
||||
|
http://www.gmayor.com/document_batch_processes.htm demonstrates a function to process all documents in a folder (and sub folders if required).
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#6
|
|||
|
|||
|
Incredible that you need this much progamming to simply see the name of the file you are editing! There must be an easier way for the name to displayed.
|
|
#7
|
||||
|
||||
|
Quote:
ActiveDocument.FullName - for the name & path ActiveDocument.Name - for the name ActiveDocument.Path - for the path
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#8
|
|||
|
|||
|
what is the single of line of code and where does it go (how is is used?)
|
|
#9
|
||||
|
||||
|
That depends on what you want to do with it. In this thread at least, you've provided nothing that could pass for context.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Active Directory Domain Services is unavailable problem October 2015 | scottstone04 | Office | 0 | 10-15-2015 01:46 PM |
Appending the filename with the current date
|
sheeand | Word VBA | 2 | 05-14-2012 05:18 AM |
How to insert current date into default filename ?
|
czomberzdaniela | Word | 1 | 12-27-2011 07:18 PM |
How to call current PC date and/or current PC year
|
KIM SOLIS | Excel | 2 | 11-04-2011 06:09 PM |
Auto insert current month's name and current year
|
Styler001 | Word | 4 | 01-25-2010 06:40 PM |