staicumihai
12-30-2015, 06:58 AM
Hy everyone, I have the following problem with a VBA macro written in Microsoft Word 2010:
Option Explicit
Sub BAAR()
Dim fisword As String
Dim folder As String
Dim primit As String
Dim cinci As String
Dim cinci1 As String
Dim raport As String
Dim BAAR As String
Dim nr As String
Dim marca As String
Dim data As String
Const strDrive As String = "D:\MIHAI\DOSARE\BAAR\"
raport = Trim(ActiveDocument.BuiltInDocumentProperties("Title").Value)
BAAR = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32)
nr = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("Company").Value), Chr(150), "")
marca = ActiveDocument.BuiltInDocumentProperties("Comments").Value
data = ActiveDocument.BuiltInDocumentProperties("Content status").Value
cinci = Right(Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32), 6)
cinci1 = Replace(cinci, " ", "")
primit = "BAAR-Dosarxxx" & "_" & cinci1 & "-" & data & " Mihai"
fisword = "R" & raport & "_" & BAAR & marca & " " & nr
folder = "BAAR-Dosar" & raport & "_" & cinci1 & " " & nr & " " & marca & "-" & data
Name strDrive & primit As strDrive & folder
' the problem is at the next two lines: instead of saving the next 2 files (word and pdf) in the path strdrive & folder, the macro saves the 2 documents in path strDrive with name folder & fisword ( I need the path to be strDrive & folder and name fisword)
ActiveDocument.SaveAs2 strDrive & folder & fisword & ".docx"
ActiveDocument.ExportAsFixedFormat OutputFileName:=strDrive & folder & fisword & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
lbl_Exit:
Exit Sub
End Sub
I wish everybody a Happy New Year !
Option Explicit
Sub BAAR()
Dim fisword As String
Dim folder As String
Dim primit As String
Dim cinci As String
Dim cinci1 As String
Dim raport As String
Dim BAAR As String
Dim nr As String
Dim marca As String
Dim data As String
Const strDrive As String = "D:\MIHAI\DOSARE\BAAR\"
raport = Trim(ActiveDocument.BuiltInDocumentProperties("Title").Value)
BAAR = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32)
nr = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("Company").Value), Chr(150), "")
marca = ActiveDocument.BuiltInDocumentProperties("Comments").Value
data = ActiveDocument.BuiltInDocumentProperties("Content status").Value
cinci = Right(Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32), 6)
cinci1 = Replace(cinci, " ", "")
primit = "BAAR-Dosarxxx" & "_" & cinci1 & "-" & data & " Mihai"
fisword = "R" & raport & "_" & BAAR & marca & " " & nr
folder = "BAAR-Dosar" & raport & "_" & cinci1 & " " & nr & " " & marca & "-" & data
Name strDrive & primit As strDrive & folder
' the problem is at the next two lines: instead of saving the next 2 files (word and pdf) in the path strdrive & folder, the macro saves the 2 documents in path strDrive with name folder & fisword ( I need the path to be strDrive & folder and name fisword)
ActiveDocument.SaveAs2 strDrive & folder & fisword & ".docx"
ActiveDocument.ExportAsFixedFormat OutputFileName:=strDrive & folder & fisword & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
lbl_Exit:
Exit Sub
End Sub
I wish everybody a Happy New Year !