I already have code to do what I want, but I would like it faster.
I copied a row from a cell, then the VBA changes the sheet, selects the row and paste the selection I copied, then saves the sheet as a PDF.
Sub Sheet2()
Selection.Copy
Sheets("Sheet2").Select
Rows("1:1").Select
ActiveSheet.Paste
Dim Path As String
Dim Sect As String
Dim Sectslash As String
Dim fisier As String
Dim director As String
Path = "C:\work"
Sect = Range("X1")
Sectslash = Range("X1") & "\"
fisier = Range("A1")
director = Path & Sectslash
If Dir(Path & Sectslash, 16) <> vbNullString Then
Else
MkDir director
End If
If IsEmpty(Range("B1")) = True Then
ActiveSheet.Copy
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & Sectslash & fisier & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWorkbook.Close False
Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).EntireRow.Select
Else
Sheets("Sheet3").Select
Rows("1:1").Select
ActiveSheet.Paste
ActiveSheet.Copy
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & uatslash & Sectslash & fisier & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWorkbook.Close False
Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).EntireRow.Select
End If
End Sub
*This is the one that doesn`t work (The line Sheets("Sheet2").Rows("1.1").Paste is not ok ): i am trying to make it faster ... i want to paste the selection to sheet2 in the first row , but without selecting the sheet2 , and save the sheet2 as PDF. i have a good code but slow , than i have what i tryed to do ... but is not working *
Sub Sheet2()
Selection.Copy
Sheets("Sheet2").Rows("1.1").Paste
Dim Path As String
Dim Sect As String
Dim Sectslash As String
Dim fisier As String
Dim director As String
Path = "C:\work\"
Sect = Sheets("Sheet2").Range("X1")
Sectslash = Sheets("Sheet2").Range("X1") & "\"
fisier = Sheets("Sheet2").Range("A1")
director = Path & Sectslash
If Dir(Path & Sectslash, 16) <> vbNullString Then
Else
MkDir director
End If
If IsEmpty(Sheets("Sheet2").Range("B1")) = True Then
Sheets("Sheet2").Copy
Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & Sectslash & fisier & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWorkbook.Close False
ActiveCell.Offset(1, 0).EntireRow.Select
Else
Selection.Copy Sheets("Sheet3").Rows("1:1").Paste
Sheets("Sheet3").Copy
Sheets("Sheet3").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & uatslash & Sectslash & fisier & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWorkbook.Close False
ActiveCell.Offset(1, 0).EntireRow.Select
End If
End Sub