modifying code to save a spesific page&range

M

Martyn

I am trying to modify the below code for taking a snapshot
& saving that as a *.gif file from a ceratain area of an XL worksheet.
The intended sheet & area is: Sheet4 Range(A1:N109)
Can anyone help please?.
--------------------
Public Sub GIF_Snapshot()
Dim varReturn As Variant
Dim MyAddress As String
Dim SaveName As Variant
Dim MySuggest As String
Dim Hi As Integer
Dim Wi As Integer
Dim Suffiks As Long

Set Sourcebok = ActiveWorkbook
MySuggest = sShortname(ActiveSheet.Name)
ImageContainer_init
Sourcebok.Activate
MyAddress = SelectArea
If MyAddress <> "A1" Then
SaveName = Application.GetSaveAsFilename( _
initialfilename:=MySuggest _
& ".gif", fileFilter:="Gif Files (*.gif), *.gif")
Range(MyAddress).Select
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlBitmap
If SaveName = False Then
GoTo Avbryt
End If
If InStr(SaveName, ".") Then SaveName _
= Left(SaveName, InStr(SaveName, ".") - 1)
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlBitmap
Hi = Selection.Height + 4
Wi = Selection.Width + 6
containerbok.Activate
ActiveSheet.ChartObjects(1).Activate
MakeAndSizeChart ih:=Hi, iv:=Wi
ActiveChart.Paste
ActiveChart.Export Filename:=SaveName & ".gif"
ActiveChart.Pictures(1).Delete
Sourcebok.Activate
End If
Avbryt:
On Error Resume Next
Application.StatusBar = False
containerbok.Saved = True
containerbok.Close
End Sub
 
S

Stevie_mac

Well, there appears to be another function in your code somewhere called...
SelectArea
Find that & modify it to select Sheet4 Range(A1:N109)

Example
Sheets("Sheet4").Activate
ActiveSheet.Range("A1:N109").Select



Better still - Add this Sub...
Sub MakeSelection(sSheetName As String, sRange As String)
Sheets(sSheetName).Activate
ActiveSheet.Range(sRange).Select
End Sub

Then call it like this...
MakeSelection "Sheet4", "A1:N109"

The reason its better is that you can easily change the function calls to adjust your range selection - also, you are
encapsulating that functionality. That makes it easy to copy / reuse / debug etc.
 
M

Martyn

Thank you Stevie_mac,
modifying SelectArea solved the problem.

Stevie_mac said:
Well, there appears to be another function in your code somewhere called...
SelectArea
Find that & modify it to select Sheet4 Range(A1:N109)

Example
Sheets("Sheet4").Activate
ActiveSheet.Range("A1:N109").Select



Better still - Add this Sub...
Sub MakeSelection(sSheetName As String, sRange As String)
Sheets(sSheetName).Activate
ActiveSheet.Range(sRange).Select
End Sub

Then call it like this...
MakeSelection "Sheet4", "A1:N109"

The reason its better is that you can easily change the function calls to
adjust your range selection - also, you are
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top