Exporteren PDF en Excel Macro

Status
Niet open voor verdere reacties.

Wouter00000

Gebruiker
Lid geworden
13 mrt 2018
Berichten
5
Goedemiddag,

Momenteel ben ik een Macro aan het schrijven. Voor mijn PDF bestand kom ik er aardig uit en heb ik alleen nog hulp nodig om de range toe te voegen. Deze moet A1: B26 zijn.


Hetzelfde bestand wil ik exporteren naar een nieuw excel werkboek(non macro) met dezelfde format, ik zou het bestand graag de naam willen geven die in cel A3 staat. Kan ik ditzelfde script met een kleine aanpassing hergebruiken?

Bekijk bijlage Voorbeeld.xlsx

sub Create_PDF()

Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler

Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "ddmmyyyy")


'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & ""

'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")

'create default name for savng file
strFile = Range("A3") & "_" & strTime
strPathFile = strPath & strFile

'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")

'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
fileName:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If

exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
 
Voorbeeldje:
Code:
Range("A1:B26").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Range("A3").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
 
en wat betreft excel?




Voorbeeldje:
Code:
Range("A1:B26").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Range("A3").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
 
Sub Copy_Selected_Range_As_New_Workbook()
Dim a As Range, rng As Range
Dim wb As Workbook
Set rng = Selection
Set wb = Workbooks.Add(xlWBATWorksheet)
For Each a In rng.SpecialCells(xlCellTypeVisible).Areas
a.Copy
With wb.ActiveSheet.Range(a(1).Address)
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlPasteFormats
End With
Next a
Application.CutCopyMode = True
End Sub


heb nu dit gebouwd, maar hoe kan ik hier een range en file naam aan toevoegen?



Daar kan je de SaveAs methode voor gebruiken:
https://www.rondebruin.nl/win/s5/win001.htm
 
Code:
sub hsv()
with workbooks.add
   thisworkbook.activesheet.range("a1:b26").copy .sheets(1).cells(1)
  .saveas "c:\users\wouter\documents\kopie", 51
end with
end sub

Verander activesheet in sheets("jebladnaam") en naar het juiste path.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan