I have such problem with my Code, I have error like this below:
Selection.MoveDown Unit:=wdLine, Count:=20
Selection.Expand wdLine
Selection.Font.Color = -603914241
strDocName = (Selection.Text)
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"\\tsclient\D\" & strDocName & ".pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
True, UseISO19005_1:=False
ChangeFileOpenDirectory "\\tsclient\D\"
I have error like this
Run time error 2147467259 (8004005)
Really need help this is my last step and it's failing
Currently I am using the code below which saves the word doc into a PDF with its default file name. I want to change it such that I can modify the PDF file name. Appreciate it!
Code:
Sub Silent_save_to_PDF()
'
' Silent Save_to_PDF Macro
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
Replace(ActiveDocument.FullName, ".docx", ".pdf") , _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
Just set the file name explicitly.
Sub Silent_save_to_PDF()
Dim extra_text As String
Dim file_name As String
extra_text = "123"
file_name = ActiveDocument.Path & "\" & Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) & extra_text & ".pdf"
ActiveDocument.ExportAsFixedFormat OutputFileName:=file_name, _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, Item:= _
wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
seems to almost work but the strlocation is showing me that there is no "\" between name of file and it's location. How do I add that.
Sub Macro1()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Range("f6").Text, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
.Subject = Range("f6").Text
.To = "EMAIL"
.Body = "Daily movement file attached" & Chr(13) & Chr(13) & _
"Regards," & Chr(13) & "SCD" & Chr(13) & "AAAAAA"
strlocation = "C:\Users\User\Desktop\macro save" & Range("f6").Text & ".pdf"
.Attachments.Add (strlocation)
.Send
End With
Set Mail_Object = Nothing
End Sub
So you're only missing a /?
Change this:
strlocation = "C:\Users\User\Desktop\macro save" & Range("f6").Text & ".pdf"
...to this:
strlocation = "C:\Users\User\Desktop\macro save\" & Range("f6").Text & ".pdf"
I am trying to save a word file in 5 different locations. My main problem is that my code only works if I specify a name in the save as part. I tried this, but with no luck:
ChangeFileOpenDirectory _
"O:\xxxx"
ActiveDocument.SaveAs FileName:=
"O:\xxxx" & Split(ActiveDocument.Name, ".")(0) & ".doc", _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
ChangeFileOpenDirectory _
"O:\xxx"
ActiveDocument.SaveAs2 FileName:= _
O:\xxxx" & Split(ActiveDocument.Name, ".")(0) & ".doc", _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
ChangeFileOpenDirectory _
"O:\xxx"
ActiveDocument.SaveAs2 FileName:= _
O:\xxxx" & Split(ActiveDocument.Name, ".")(0) & ".doc", _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
ChangeFileOpenDirectory _
"O:xxxx"
ActiveDocument.SaveAs2 FileName:= _
O:\xxxx" & Split(ActiveDocument.Name, ".")(0) & ".doc", _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
ChangeFileOpenDirectory _
"O:\xxx"
ActiveDocument.SaveAs2 FileName:= _
O:\xxxx" & Split(ActiveDocument.Name, ".")(0) & ".doc", _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=15
The file paths are all different but the filename should be the same. It basically should just take the name of the opened document.
well, I would do it in a loop:
Sub daf()
Dim docCopy As Document
Dim sPath(4) As String
Dim sFileName As String
Dim i As Long
sPath(0) = "C:\zzz"
sPath(1) = "c:\ddd"
sPath(2) = "C:\ttt"
sPath(3) = "C:\yyy"
sPath(5) = "C:\ooo"
sFileName = Split(ActiveDocument.Name, ".")(0)
Set docCopy = Application.Documents.Add(ActiveDocument.FullName)
For i = 0 To UBound(sPath)
docCopy.SaveAs2 sPath & "\" & sFileName & ".doc", 12
Next i
End Sub
You can add more arguments to saveAs2 if you wish, as you did in your original macro.
I have some problem with my mailmerge macro in this part:
wdocSource.Mailmerge.OpenDataSource _
Name:=strWorkbookName, _
AddToRecentFiles:=False, _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="Data Source=" & strWorkbookName & ";Mode=Read", _
SQLStatement:="SELECT * FROM `Mailing$`"
Can somebody help me change the connection settings? I am try many ways but always dont run correctly.