File Save as and pasting from clipboard in VBA macro

sshishirkumar

New Member
Joined
Mar 1, 2012
Messages
4
Hi
I have the following code which is pasting the same hard coded value every time (Test File.doc) instead of pasting from clipboard, Please help me change the code to pate from clipboard while renaming the file using save as.

ChangeFileOpenDirectory "C:\Documents and Settings\ssankees\Desktop\"
ActiveDocument.SaveAs2 FileName:= _
"Test File.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=0
 

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
3,547
??? Where is the paste taking place? This is only save a file.
 

sshishirkumar

New Member
Joined
Mar 1, 2012
Messages
4
??? Where is the paste taking place? This is only save a file.
Thanks, I found the solution to my problem. I wanted to paste the file name which was stored in the clipboard.

Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
Dim my_filename As String

my_filename = DataObj.GetText

ActiveDocument.SaveAs2 FileName:= _
my_filename, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=0
 

Forum statistics

Threads
1,085,494
Messages
5,383,994
Members
401,871
Latest member
allemandi

Some videos you may like

This Week's Hot Topics

Top