Consulting

Results 1 to 13 of 13

Thread: word 2007 save as macro

  1. #1

    word 2007 save as macro

    i am a total newbie and was trying to get a macro to work in word 2007 which involves a SAVE AS functionality

    all i want to do is get SAVE AS to save my file with CLIPBOARD as the FILENAME

    I was recording it and something like this was the result

    ActiveDocument.PrintOut
        ChangeFileOpenDirectory "F:\vaseem\today\"
        ActiveDocument.SaveAs FileName:="sefsdtg.docx", FileFormat:= _
            wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
            :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
            :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
            SaveAsAOCELetter:=False
    Now the what i understand from above is its saving the file as "sefsdtg" which i had typed randomly at the time of recording.

    ANY HELP IS APPRECIATED

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    What you said was that you want the file name to be "CLIPBOARD.docx," but I think that you want the name to be the contents of the clipboard, AKA, whatever you just copied

    IF you are copying the desired name from the document itself, then
    ActiveDocument.SaveAs FileName:=Selection & ".docx"
    Note that you only have to select the name, you don't have to copy it.

    If you copied the name from something else, you will have to use a DataObject to receive the contents of the clipboard.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Jul 2013
    Posts
    9
    Location

    How can i modify this

    hey thats a code of a macro...which crops images on every page of the word file...but right now it gets a runtime error if it encounters more than or less than 8 pages in the word file...I need to modify it so that it does the cropping at each page till the end of the word file no matter any no. of pages..How can i modify the code like that ....Can anyone tell me what is the significance of word inline shape(1) and (2) and so on...does it means images on page 1 , 2 and so on ?..My understanding is that i need to use loop for the code With ActiveDocument.InlineShapes(1)once instead for till upto (7)
    the faulty code..

    Sub CropImageMacro()
        ' CropImageMacro Macro
        ' This Macro Crops unwanted parts of an image
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.MoveRight Unit:=wdCharacter, Count:=20, Extend:=wdExtend
        Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
        Selection.Delete Unit:=wdCharacter, Count:=1
        Application.Templates.LoadBuildingBlocks
        Dim sngHeight, sngWidth, sngCropTop, sngCropBottom As Single
        sngCropTop = 0.154
        sngCropBottom = 0.05
        With ActiveDocument.InlineShapes(1)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
            .Width = .Width
        End With
        sngCropTop = 0.014
        sngCropBottom = 0.069
        With ActiveDocument.InlineShapes(2)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
            .Width = .Width
        End With
        With ActiveDocument.InlineShapes(3)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
            .Width = .Width
        End With
        With ActiveDocument.InlineShapes(4)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
            .Width = .Width
        End With
        With ActiveDocument.InlineShapes(5)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
            .Width = .Width
        End With
        With ActiveDocument.InlineShapes(6)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
             Width = .Width
        End With
        With ActiveDocument.InlineShapes(7)
            sngHeight = .Height
            sngWidth = .Width
            With .PictureFormat
                .CropTop = sngHeight * sngCropTop
                .CropBottom = sngHeight * sngCropBottom
            End With
            .Height = .Height
            .Width = .Width
        End With
    End Sub

  4. #4
    VBAX Regular
    Joined
    Jul 2013
    Posts
    9
    Location
    Mr. sam can you help me on that?

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    If you're not taking the file name from a word Document, you'll have to tell me where it is coming from.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Regular
    Joined
    Jul 2013
    Posts
    9
    Location
    I have a directory with X number of word 2007 docX files.
    I open each file and run a macro to crop the images on each of the pages.

  7. #7
    VBAX Regular
    Joined
    Jul 2013
    Posts
    9
    Location
    The current macro I have only crops images upto 8 pages. It also gives
    a run command error if it encounters only 7 pages in the document and
    the macro gets funky . I want it to not freak out and give error
    messages if ever it does encounter less than 8 pages, and neither do I
    want it to stop doing its job if it encounters more than 8 pages.

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Okay, bye.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    What on earth does cropping images have to do with your subject about saving the filename?

  10. #10
    Quote Originally Posted by fumei View Post
    What on earth does cropping images have to do with your subject about saving the filename?
    there was a second question from NEWBEE which had nothin to do with me the original poster of the CLIPBOARD RENAME problem with name VASEEMALI

    TWO DIFFERENT PEOPLE WITH DIFFERENT QUESTIONS

  11. #11
    Quote Originally Posted by SamT View Post
    What you said was that you want the file name to be "CLIPBOARD.docx," but I think that you want the name to be the contents of the clipboard, AKA, whatever you just copied

    IF you are copying the desired name from the document itself, then
    ActiveDocument.SaveAs FileName:=Selection & ".docx"
    Note that you only have to select the name, you don't have to copy it.

    If you copied the name from something else, you will have to use a DataObject to receive the contents of the clipboard.
    WORKED LIKE A CHARM...THANKS

  12. #12
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Thank you for clearing up the double questions. I was set to ignore this thread after Newbee confused me.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yeah I missed that as well.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •