PDA

View Full Version : [SOLVED:] word 2007 save as macro



vaseemali
07-27-2013, 03:28 AM
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

SamT
07-27-2013, 07:17 AM
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.

newbee
07-27-2013, 09:07 AM
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

newbee
07-27-2013, 09:09 AM
Mr. sam can you help me on that?

SamT
07-27-2013, 09:23 AM
If you're not taking the file name from a word Document, you'll have to tell me where it is coming from.

newbee
07-27-2013, 09:48 AM
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.

newbee
07-27-2013, 09:50 AM
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.

SamT
07-27-2013, 09:56 AM
Okay, bye.

fumei
07-28-2013, 09:45 PM
What on earth does cropping images have to do with your subject about saving the filename?

vaseemali
07-29-2013, 12:10 AM
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

vaseemali
07-29-2013, 12:11 AM
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

SamT
07-29-2013, 10:41 AM
Thank you for clearing up the double questions. I was set to ignore this thread after Newbee confused me.

fumei
07-29-2013, 01:15 PM
Yeah I missed that as well.