Hello,
I was wondering how can I get the set PrintArea of a sheet and use that address to copy over to another sheet.
Lets call the PrintArea sheet .. Sheet1 and the destination Sheet2
Sheet1 will be a sheet that has been imported from a file. The printareas are all going to be different so I cant just use one range. The print area is set and saved when the file was originally saved. If I can access it while importing, because for some reason, once it is imported the print area is lost. So if I could open the file get the print area first then import it that would be very helpful.
That way once I import the file to Sheet1, I could use that address and copy the previously set PrintArea to Sheet2.
Is there a way to do that?
This is the function I use to open a file for importing.
I was wondering how can I get the set PrintArea of a sheet and use that address to copy over to another sheet.
Lets call the PrintArea sheet .. Sheet1 and the destination Sheet2
Sheet1 will be a sheet that has been imported from a file. The printareas are all going to be different so I cant just use one range. The print area is set and saved when the file was originally saved. If I can access it while importing, because for some reason, once it is imported the print area is lost. So if I could open the file get the print area first then import it that would be very helpful.
That way once I import the file to Sheet1, I could use that address and copy the previously set PrintArea to Sheet2.
Is there a way to do that?
This is the function I use to open a file for importing.
Code:
Private Sub ImportBut_Click()
Unload entryform
Sheets("Import").Range("A1:BG9999").Clear
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim Sheet As Worksheet
Dim PasteStart As Range
Set wb1 = ActiveWorkbook
Set PasteStart = [Import!A1]
Sheets("Import").Select
Cells.Select
Selection.ClearContents
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a Template to Import", _
FileFilter:="Report Files *.xlsx (*.xlsx),")
If FileToOpen = False Then
MsgBox "No File Specified.", vbExclamation, "ERROR"
Exit Sub
Else
Set wb2 = Workbooks.Open(Filename:=FileToOpen)
For Each Sheet In wb2.Sheets
If Sheet.Name = "Datasheet-C" Then
With Sheet.UsedRange
.Copy PasteStart
Set PasteStart = PasteStart.Offset(.Rows.Count)
End With
End If
If Sheet.Name = "Datasheet" Then
With Sheet.UsedRange
.Copy PasteStart
Set PasteStart = PasteStart.Offset(.Rows.Count)
End With
End If
Next Sheet
End If
wb2.Close
Call ImportDS
End Sub