code to save only current page as PDF

Started by kiler40, April 12, 2014, 06:36:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kiler40

Hello All,

I`m really bad in coding but i`m looking for a code to save only the current page as pdf, and to put the name of the saved file as one of the shapes data field.

i`m attaching a sample file with 2 pages.
i want to save the second page as pdf and make the file name equal to the field "used" of the shape.

Any ideas ?

Thanks in advance.

Surrogate

Quotehttp://msdn.microsoft.com/en-us/library/office/ms409271(v=office.12).aspx
expression.ExportAsFixedFormat(FixedFormat, OutputFileName, Intent, PrintRange, FromPage, ToPage, ColorAsBlack, IncludeBackground, IncludeDocumentProperties, IncludeStructureTags, UseISO19005_1, FixedFormatExtClass)
try ExportAsFixedFormat
1. This is fastest way
2. You can save your PDF with needed name

kiler40

ok. this is nice. thank you.

but what about the text in the field of a shape.

i`m reading around the net, but i cannot really understand...
little more help please. :)

Surrogate

#3
This method availible in Visio 2007, 2010, 2013. On my PC at home i have got Visio 2003.
I published in russian visio forum this macro, but there i convert all pages.
Private Declare Function ShellExecute Lib "shell32.dll" Alias _  "ShellExecuteA" (ByVal hwnd As Long, _  ByVal lpOperation As String, _  ByVal lpFile As String, _  ByVal lpParameters As String, _  ByVal lpDirectory As String, _  ByVal nShowCmd As Long) As Long
Const SW_SHOWMAXIMIZED = 3
Sub ExportToPDF()
Dim VD As Document ' переменная - текущий документ
Set VD = ActiveDocument
Dim fn As String ' переменная - имя текущего файла
fn = VD.Path & VD.Name ' получаем полное имя текущего документа
Dim ext As String  ' переменная - расширение текущего документа
ext = ".vsd" ' по умолчанию ставим такое расширение
If VD.Application.Version > "14.0" Then ext = ".vsdx" ' если документ имеет версию старше 2010, то изменяем текущее расширение
Dim suff As String  ' переменная - окончание названия создаваемого файла PDF
suff = "_" & Format(Now, "ddMMyy") & "-" & Format(Now, "hhmmss") & ".pdf" ' добавляем к перед расширением текущую дату и время
dim pdf_n As String ' переменная - имя создаваемого файла PDF
pdf_n = Replace(fn, ext, suff) ' получаем имя создаваемого файла PDF, производим замену расширения vsd(vsdx) на pdf, с добавлением даты и времени
VD.ExportAsFixedFormat visFixedFormatPDF, pdf_n, visDocExIntentPrint, visPrintAll, , , , False, False, False ' экспорт документа в файл PDF
Call ShellExecute(0, "open", pdf_n, "", "", SW_SHOWMAXIMIZED) ' открываем полученный PDF файл
End Sub

try this modified row
VD.ExportAsFixedFormat visFixedFormatPDF, pdf_n, visDocExIntentPrint, visPrintFromTo, 2, 2
Quotebut what about the text in the field of a shape.
???

kiler40

Quotebut what about the text in the field of a shape.

One off the sapes have 3 data fields (prop.row_1,2,3 etc.)
i want the text that is in one of this fields to be the name of the saved file.
because it is changing every time.

Surrogate

in your file on second page i see one shape with 3 shape data, which of these shapedata will be a name of PDF file ?


Surrogate

try this little code :)
Sub ExportToPDF()
Dim pdf_n As String
pdf_n = ActiveDocument.Path & ActiveDocument.Pages(2).Shapes(1).Cells("prop.used") & ".pdf"
ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, pdf_n, visDocExIntentPrint, visPrintFromTo, 2, 2
End Sub

kiler40

this is what it is :)
but i cannot understand why it i returning 0 if i write text in the field ?
if i write number the output is number. if i write text the oputput is 0

Surrogate

oh, sorry ! when i add .ResultStr("") in pdf file name, it works correct
Sub ExportToPDF()
Dim pdf_n As String
pdf_n = ActiveDocument.Path & ActiveDocument.Pages(2).Shapes(1).Cells("prop.used").ResultStr("") & ".pdf"
ActiveDocument.ExportAsFixedFormat visFixedFormatPDF,pdf_n, visDocExIntentPrint, visPrintFromTo, 2, 2
End Sub

kiler40