Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-16-2015, 01:03 AM
gazeranco gazeranco is offline Problem getting filename and directory of current word doc. Windows 7 64bit Problem getting filename and directory of current word doc. Office 2010 64bit
Novice
Problem getting filename and directory of current word doc.
 
Join Date: Dec 2015
Posts: 5
gazeranco is on a distinguished road
Question Problem getting filename and directory of current word doc.


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
 



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
Problem getting filename and directory of current word doc. Appending the filename with the current date sheeand Word VBA 2 05-14-2012 05:18 AM
Problem getting filename and directory of current word doc. How to insert current date into default filename ? czomberzdaniela Word 1 12-27-2011 07:18 PM
Problem getting filename and directory of current word doc. How to call current PC date and/or current PC year KIM SOLIS Excel 2 11-04-2011 06:09 PM
Problem getting filename and directory of current word doc. Auto insert current month's name and current year Styler001 Word 4 01-25-2010 06:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:09 PM.


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