Dilermando
05-26-2015, 04:08 AM
Hello. That’s is my situation:
1 - file "cadastrar paciente.xls" has just one spreadsheet: "cadastrar paciente" and two macros: "gravar paciente" and "imprimir ficha paciente"
2 - file "cadastro pacientes.xls" has two spreadsheets: "cadastro pacientes" and "agenda"
3 – after opening "cadastro pacientes.xls", I type a few data in spreadsheet "cadastrar paciente"
4 – then I run macro "gravar paciente" (in "cadastrar paciente.xls"), to save such data in spreadsheet "cadastro pacientes" (located in in the other file "cadastro pacientes.xls")
5 - macro "imprimir ficha paciente" was automatically created, it’s purpose is to print a fixed range of cells belonging to spreadsheet "cadastrar paciente" (located in "cadastrar paciente.xls")
6 - however, macro "imprimir ficha paciente" doesn’t work as designed, it starts opening the wrong spreadsheet "cadastro pacientes" - which is located in the wrong file "cadastro pacientes.xls - then it freezes (no error message is displayed, anytime)
7 - I guess some clever trick is lacking, how to tell my macro to go the right way, that is, to pick up a range of cells in spreadsheet "cadastrar paciente" (located in "cadastrar paciente.xls"), then proceed to printing ?
Your help will be fully appreciated. Thank you !
**********************************************************
macro "imprimir ficha paciente" (located in "cadastrar paciente.xls")
Sub imprimir_ficha_paciente()
' selecionar dados para impressão da ficha do paciente
Range("G4:H22").Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.511811023622047)
.RightMargin = Application.InchesToPoints(0.511811023622047)
.TopMargin = Application.InchesToPoints(0.78740157480315)
.BottomMargin = Application.InchesToPoints(0.78740157480315)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Selection.PrintOut Copies:=1, Collate:=True
Range("A1").Select
End Sub
1 - file "cadastrar paciente.xls" has just one spreadsheet: "cadastrar paciente" and two macros: "gravar paciente" and "imprimir ficha paciente"
2 - file "cadastro pacientes.xls" has two spreadsheets: "cadastro pacientes" and "agenda"
3 – after opening "cadastro pacientes.xls", I type a few data in spreadsheet "cadastrar paciente"
4 – then I run macro "gravar paciente" (in "cadastrar paciente.xls"), to save such data in spreadsheet "cadastro pacientes" (located in in the other file "cadastro pacientes.xls")
5 - macro "imprimir ficha paciente" was automatically created, it’s purpose is to print a fixed range of cells belonging to spreadsheet "cadastrar paciente" (located in "cadastrar paciente.xls")
6 - however, macro "imprimir ficha paciente" doesn’t work as designed, it starts opening the wrong spreadsheet "cadastro pacientes" - which is located in the wrong file "cadastro pacientes.xls - then it freezes (no error message is displayed, anytime)
7 - I guess some clever trick is lacking, how to tell my macro to go the right way, that is, to pick up a range of cells in spreadsheet "cadastrar paciente" (located in "cadastrar paciente.xls"), then proceed to printing ?
Your help will be fully appreciated. Thank you !
**********************************************************
macro "imprimir ficha paciente" (located in "cadastrar paciente.xls")
Sub imprimir_ficha_paciente()
' selecionar dados para impressão da ficha do paciente
Range("G4:H22").Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.511811023622047)
.RightMargin = Application.InchesToPoints(0.511811023622047)
.TopMargin = Application.InchesToPoints(0.78740157480315)
.BottomMargin = Application.InchesToPoints(0.78740157480315)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Selection.PrintOut Copies:=1, Collate:=True
Range("A1").Select
End Sub