Notifications
Clear all

SaveCopyAs FileFormat

5 Posts
2 Usuários
0 Reactions
1,125 Visualizações
(@alanisfcsm)
Posts: 0
Trusted Member
Topic starter
 

Boa tarde!

O código abaixo salva em 'PDF' planilhas com 'V2' igual a '1'.

Seria possível além de salvar em 'PDF' salvar também em 'XLS' na pasta 'D:XLS' com o mesmo nome do 'PDF' usando SaveCopyAs?


Sub Mail_Every_Worksheet_With_Address_In_A1_PDF_CRIA_PDF_DA_PAGINA_PREENCHIADA()

Application.ScreenUpdating = False

    Dim Sh As Worksheet
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileName As String
 
    For Each Sh In Worksheets
            Sh.Visible = xlSheetVisible
    Next Sh
   
    TempFilePath = Environ$("temp") & ""
    TempFilePath = "D:PVPDF"

    For Each Sh In ThisWorkbook.Worksheets
        FileName = ""

        If Sh.Range("V2").Value Like "1" Then
              
             TempFileName = TempFilePath _
                         & Sheets("SET").Range("K19") _
                         & " - " _
                         & Sheets("A").Range("D1").Value _
                         & "" _
                         & Format(Sheets("SET").Range("B332").Value, "00000") _
                         & " - " _
                         & Format(Now, "dd-mm-yyyy") _
                         & ".pdf"

            FileName = RDB_Create_PDF(source:=Sh, _
                                      FixedFilePathName:=TempFileName, _
                                      OverwriteIfFileExist:=True, _
                                      OpenPDFAfterPublish:=False)
                                   
            End If
        
    Next Sh
    
    For Each Sh In Worksheets

        If UCase(Sh.Name) <> UCase("A") Then
            Sh.Visible = xlSheetVeryHidden
        End If

    Next Sh
    
    Application.ScreenUpdating = True
    
End Sub


 
Postado : 26/09/2016 2:30 pm
Basole
(@basole)
Posts: 487
Reputable Member
 

Fiz as alteraçoes solicitadas.
Veja se é isso,
Pois não pude testar aqui:

Sub Mail_Every_Worksheet_With_Address_In_A1_PDF_CRIA_PDF_DA_PAGINA_PREENCHIADA()

    Application.ScreenUpdating = False

    Dim Sh As Worksheet
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileName As String

    For Each Sh In Worksheets
        Sh.Visible = xlSheetVisible
    Next Sh

    TempFilePath = Environ$("temp") & ""
    TempFilePath = "D:PVPDF"

    For Each Sh In ThisWorkbook.Worksheets
        FileName = ""

        If Sh.Range("V2").Value Like "1" Then

            TempFileName = TempFilePath _
                           & Sheets("SET").Range("K19") _
                           & " - " _
                           & Sheets("A").Range("D1").Value _
                           & "" _
                           & Format(Sheets("SET").Range("B332").Value, "00000") _
                           & " - " _
                           & Format(Now, "dd-mm-yyyy") _
                           & ".pdf"

            FileName = RDB_Create_PDF(Source:=Sh, _
                                      FixedFilePathName:=TempFileName, _
                                      OverwriteIfFileExist:=True, _
                                      OpenPDFAfterPublish:=False)

            TempFilePath = "D:XLS"
            
            TempFileName = TempFilePath _
                           & Sheets("SET").Range("K19") _
                           & " - " _
                           & Sheets("A").Range("D1").Value _
                           & "" _
                           & Format(Sheets("SET").Range("B332").Value, "00000") _
                           & " - " _
                           & Format(Now, "dd-mm-yyyy") _
                           & ".xls"
                             ' salva formato xls
            ActiveWorkbook.SaveAs TempFileName, FileFormat:=52

        End If

    Next Sh

    For Each Sh In Worksheets

        If UCase(Sh.Name) <> UCase("A") Then
            Sh.Visible = xlSheetVeryHidden
        End If

    Next Sh

    Application.ScreenUpdating = True

End Sub

Click em se a resposta foi util!

 
Postado : 26/09/2016 5:56 pm
(@alanisfcsm)
Posts: 0
Trusted Member
Topic starter
 

Bom dia Basole.
Agradeço pela paciência.

Negativo. O código salva a planilha inteira.

Gostaria de salvar em 'XLS' somente a planilha em que a célula "V2" for igual a "1". Como acontece com o 'PDF'.

 
Postado : 27/09/2016 6:40 am
Basole
(@basole)
Posts: 487
Reputable Member
 

Boa tarde,
Veja agora, com as alterações:

Salva no Formato *.xls (excel 97/2003 *conf. solicitado)

Sub Mail_Every_Worksheet_With_Address_In_A1_PDF_CRIA_PDF_DA_PAGINA_PREENCHIADA()

    Application.ScreenUpdating = False

    Dim Sh As Worksheet
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileName As String

    For Each Sh In ThisWorkbook.Worksheets
        Sh.Visible = xlSheetVisible
    Next Sh

    TempFilePath = Environ$("temp") & ""
    TempFilePath = "D:PVPDF"

    For Each Sh In ThisWorkbook.Worksheets
        FileName = ""

        If Sh.Range("V2").Value Like "1" Then

            TempFileName = TempFilePath _
                           & Sheets("SET").Range("K19") _
                           & " - " _
                           & Sheets("A").Range("D1").Value _
                           & "" _
                           & Format(Sheets("SET").Range("B332").Value, "00000") _
                           & " - " _
                           & Format(Now, "dd-mm-yyyy") _
                           & ".pdf"

            FileName = RDB_Create_PDF(Source:=Sh, _
                                      FixedFilePathName:=TempFileName, _
                                      OverwriteIfFileExist:=True, _
                                      OpenPDFAfterPublish:=False)

            TempFilePath = "D:XLS"

            TempFileName = TempFilePath _
                           & Sheets("SET").Range("K19") _
                           & " - " _
                           & Sheets("A").Range("D1").Value _
                           & "" _
                           & Format(Sheets("SET").Range("B332").Value, "00000") _
                           & " - " _
                           & Format(Now, "dd-mm-yyyy") _
                           & ".xls"

            Dim wb As Workbook
            Set wb = Workbooks.Add
            Sh.Copy Before:=wb.Sheets(1)
            ' salva formato xls
            wb.SaveAs TempFileName, FileFormat:=56
            wb.Close savechanges:=True

        End If

    Next Sh
    ThisWorkbook.Activate
    For Each Sh In ThisWorkbook.Worksheets

        If UCase(Sh.Name) <> UCase("A") Then
            Sh.Visible = xlSheetVeryHidden
        End If

    Next Sh

    Application.ScreenUpdating = True

End Sub

Click em se a resposta foi util!

 
Postado : 27/09/2016 9:03 am
(@alanisfcsm)
Posts: 0
Trusted Member
Topic starter
 

Perfeito!
Obrigado! Basole
Agradeço mais uma vez pelo tempo e paciência.

:D :D :D :D :D

 
Postado : 27/09/2016 9:30 am