This macro is not working correctly. The desired output is that automatically change the values of one cell (a list) that is formulated to change other info in the same page.
Currently is printing the whole list correctly but is not changing the info in the other cells, even tho this formulas are correct and working accordingly.
"
Sub Imprimir()
' SET UP APP -------------------
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Application.Calculation = xlManual
Application.DisplayAlerts = False
ThisWorkbook.Activate
' INICIO -------------------
N = Sheets("Ficha Resumen_ajustada").Range("Q1").Value
For i = 1 To N
Sheets("Ficha Resumen_ajustada").Range("I7").Value = Sheets("Base").Cells(8 + i, 1).Value
With Worksheets("Ficha Resumen_ajustada")
'obj_visiibility = .Visible
'.Visible = xlSheetVisible
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "_" & CStr(Sheets("Base").Cells(8 + i, 1).Value), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'.Visible = obj_visibility
End With
Next
' FIN -------------------
' SET UP APP -------------------
Application.DisplayAlerts = True
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End Sub
"
any idea why is this happening ?
Related
Below code works perfectly in creating PDFs from an Excel table PivotTable and slicer however falls short when connected to a PowerPivot PivotTable with a slicer. I attempted with the modified query below but keep errorring when it get to this portion of the code:
If sI.Name = slDummy.Name Then slDummy.Selected = True Else: slDummy.Selected = False
If sC.SlicerCacheLevels(1).Count = 1 Then
Sub PDF()
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = FALSE
.DisplayStatusBar = FALSE
.EnableEvents = FALSE
.DisplayAlerts = FALSE
End With
Dim slItem As SlicerItem
Dim slDummy As SlicerItem
Dim slBox As SlicerCache
Dim FilePath As String
FilePath = "\\cdcsrvr1\Depts\C&I_Sales_Mgmt_Admin\POS_Reports\A_SALES_CREDIT\Agency Reports\"
Set slBox = Workbooks("POT_POS Sales Credit MASTER.xlsm").SlicerCaches("Slicer_RollUp_Agent")
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
MsgBox ("Letsa Go!")
For Each slItem In slBox.SlicerItems
slBox.ClearManualFilter
For Each slDummy In slBox.SlicerItems
If slItem.Name = slDummy.Name Then slDummy.Selected = TRUE Else: slDummy.Selected = FALSE
If slBox.VisibleSlicerItems.Count = 1 Then
Application.CalculateFull
On Error Resume Next
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FilePath & Sheets("Dashboard").Range("B4") & " " & Sheets("Dashboard").Range("C10") & " - " & "R" & Sheets("Dashboard").Range("C5") & " - POT_POS SALES CREDIT - " & Sheets("Dashboard").Range("C6") & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
On Error GoTo 0
End If
Next slDummy
Next slItem
ActiveWorkbook.SlicerCaches("Slicer_RollUp_Agent").ClearManualFilter
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = TRUE
.DisplayStatusBar = TRUE
.EnableEvents = TRUE
.DisplayAlerts = TRUE
End With
End Sub
Below you can find my code that is working for a certain area. But I want to add a new element in the code but I can't find it how I can do it. The first area is A1:E42, but now I have one worksheet where I have 3 area. A1:E42, H1:K42 and O1:R42). How do I need to rewrite my code that the first area comes on the first pdf page, the second area on the second page et cetera.
Sub SavePDF()
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
With ws.PageSetup
.Orientation = xlLandscape
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
.PrintArea = "A1:E42"
End With
Set ws = Nothing
Sheets("Offerte_M").ExportAsFixedFormat x1TypePDF, Filename:= _
"C:\Intel\" & ActiveSheet.Range("F21").Value & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
MsgBox "Offerte has been saved as PDF. Press send now."
I thought maybe this was the correct way, but that doesn't work also.
Sub CommandButton1_Click()
Application.ScreenUpdating = False
Offerte_M.PageSetup.PrintArea = "A1:E42"
Offerte_M.PageSetup.PrintArea = "H1:K42"
Offerte_M.PageSetup.PrintArea = "O1:R42"
Worksheets(Array("Offerte_M")).Select.ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\Intel\" & ActiveSheet.Range("F21").Value & ".pdf", _
OpenAfterPublish:=True
Offerte_M.PageSetup.PrintArea = ""
Offerte_M.PageSetup.PrintArea = ""
Offerte_M.PageSetup.PrintArea = ""
Offerte_M.Select
Application.ScreenUpdating = True
End Sub
I have a macro that prints a chart to pdf by copying the chart to a new sheet (wstemp) and printing the new sheet. The macro works fine on my computer and my wife's, but not on the client's. He continues to get the '1004' error "paste method of range class failed". Code below, the error is on the paste line. Any thoughts would be greatly appreciated.
Sub PrintPDFLDRBD_Chart1()
'
' prints my ldr bd
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ch1 As Shape
Dim pth, nme, fn, lft, chd As String
Dim wsref, wstemp As Worksheet
Set wsref = ThisWorkbook.Sheets("SheetA")
Set ch1 = wsref.Shapes("SheetAChart1")
pth = ThisWorkbook.path
fn = pth & "\" & "SheetA_ch1"
Set wstemp = Sheets.Add
ch1.Copy
wstemp.Range("A1").PasteSpecial
With wstemp.PageSetup
.RightHeader = Format(Now, "MMMM DD, YYYY HH:MM:SS")
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
wstemp.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
fn, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=True, OpenAfterPublish:=True
wstemp.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
So I have a worksheet with a landscape orientation that I am exporting to a PDF. I can achieve this without any issues by selecting the usedRange of the activesheet, but the content prints to just one page, even if the used range is outside of the print area. How might I go about getting it to print a multi-page PDF in this case? My code is below:
Dim numSheets As Integer
numSheets = UBound(SlotArray)
For z = LBound(SlotArray) To UBound(SlotArray)
Set attendSh = ThisWorkbook.Sheets(SlotArray(z))
attendSh.Activate
ThisWorkbook.ActiveSheet.UsedRange.Select
Next z
Select Case numSheets
Case "0"
ThisWorkbook.Sheets(Array(SlotArray(0))).Select
Case "1"
ThisWorkbook.Sheets(Array(SlotArray(0), SlotArray(1))).Select
Case "2"
ThisWorkbook.Sheets(Array(SlotArray(0), SlotArray(1), SlotArray(2))).Select
Case "3"
ThisWorkbook.Sheets(Array(SlotArray(0), SlotArray(1), SlotArray(2), SlotArray(3))).Select
Case "4"
ThisWorkbook.Sheets(Array(SlotArray(0), SlotArray(1), SlotArray(2), SlotArray(3), SlotArray(4))).Select
Case "5"
ThisWorkbook.Sheets(Array(SlotArray(0), SlotArray(1), SlotArray(2), SlotArray(3), SlotArray(4), SlotArray(5))).Select
Case "6"
ThisWorkbook.Sheets(Array(SlotArray(0), SlotArray(1), SlotArray(2), SlotArray(3), SlotArray(4), SlotArray(5), SlotArray(6))).Select
End Select
Application.PrintCommunication = False
With ThisWorkbook.ActiveSheet.PageSetup
.Orientation = xlLandscape
.CenterHorizontally = True
'.Zoom = 90
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintComments = False
.PrintGridlines = False
End With
Application.PrintCommunication = True
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
FilePath & "\" & Year & " Monthly Attendance\" & "\" & Year & " " & Month & " Attendance.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
where slotArray is an array of sheet names.
Try applying the PageSetUp to every sheet in the array.
Dim numSheets As Long, Z As Long
numSheets = UBound(SlotArray)
Dim ws As Worksheet
For Z = LBound(SlotArray) To UBound(SlotArray)
Set ws = ThisWorkbook.Sheets(SlotArray(Z))
With ws.PageSetup
.Orientation = xlLandscape
.CenterHorizontally = True
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintComments = xlPrintNoComments
.PrintGridlines = False
.PrintArea = ws.UsedRange.Address
End With
Next Z
ThisWorkbook.Sheets(SlotArray).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="Attendance.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox "Printed " & vbLf & Join(SlotArray, vbLf)
I have large spreadsheet that I'm looping through and printing each page to a pdf report.
I'm trying to print them A3 Landscape, however the actual export size is far larger than an A3 page.
Any suggestions I what I'm doing wrong?
Here is my current code:
Sub printChartsA3()
Application.ScreenUpdating = False
Dim sPrintArea As String
Dim wks As Worksheet
Const path As String = "E:\A3 Charts\"
sPrintArea = "A1:BM69"
For Each wks In Worksheets
Application.PrintCommunication = False
wks.PageSetup.PaperSize = xlPaperA3
wks.PageSetup.Orientation = xlLandscape
wks.PageSetup.LeftMargin = Application.InchesToPoints(0.25)
wks.PageSetup.RightMargin = Application.InchesToPoints(0.25)
wks.PageSetup.PrintArea = sPrintArea
wks.PageSetup.Zoom = False
wks.PageSetup.FitToPagesWide = 1
'wks.PageSetup.FitToPagesTall = 1 'not sure if this one is needed?
Application.PrintCommunication = True
wks.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=path & wks.Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next
Set wks = Nothing
Application.ScreenUpdating = True
End Sub