You are on page 1of 2

Public Function CopySheetFromAnotherFileFormat(SourcePath As String, SourceSheet As

String, DestinationSheet As String) As Boolean

On Error GoTo Exception

Application.DisplayAlerts = False

Dim SourceWorkbook As Workbook


Set SourceWorkbook = Workbooks.Open(SourcePath)
SourceWorkbook.Sheets(SourceSheet).Select

If Application.ActiveSheet.UsedRange.Rows.Count > 1 Then

ActiveSheet.Rows("2:" & Application.ActiveSheet.UsedRange.Rows.Count).Select


Selection.Copy

End If

ThisWorkbook.Activate
Sheets(DestinationSheet).Range("A2").PasteSpecial Paste:=xlPasteFormats
Sheets(DestinationSheet).Range("A2").PasteSpecial
Paste:=xlPasteValuesAndNumberFormats

SourceWorkbook.Save
SourceWorkbook.Close
CopySheetFromAnotherFileFormat=True

Done:
Exit Function

Exception:
CopySheetFromAnotherFileFormat=False

End Function

Public Function ClearContent(DestinationSheet As String) As Boolean


On Error GoTo Exception
Application.DisplayAlerts = False

Worksheets(DestinationSheet).Activate

If Application.ActiveSheet.UsedRange.Rows.Count > 1 Then

ActiveSheet.Rows("2:" &
Application.ActiveSheet.UsedRange.Rows.Count).ClearContents

End If

ThisWorkBook.Save

ClearContent=True
Done:
Exit Function

Exception:
ClearContent=False

End Function

Public Function CopySheetFromAnotherFileFormatTemp(SourcePath As String,


SourceSheet As String, DestinationSheet As String) As Boolean

Application.DisplayAlerts = False

Dim SourceWorkbook As Workbook


Set SourceWorkbook = Workbooks.Open(SourcePath)
SourceWorkbook.Sheets(SourceSheet).Select
ActiveCell = Range("A2")
Range(ActiveCell, ActiveCell.End(xlDown).End(xlToRight)).Select
Cells.Select
Selection.Copy

End If

ThisWorkbook.Activate
Sheets(DestinationSheet).Range("A2").PasteSpecial Paste:=xlPasteFormats
Sheets(DestinationSheet).Range("A2").PasteSpecial
Paste:=xlPasteValuesAndNumberFormats

SourceWorkbook.Save
SourceWorkbook.Close
CopySheetFromAnotherFileFormat=True

End Function

You might also like