Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default What is wrong with this code? Screen capture and export as image?

Fellow programmers,

I have written a code to screencapture my current desktop and paste
it as a chart object -- so that Excel can export what it
screencaptured. The code works -- it's just that the picture is really
tiny... any ideas? Below is my code -- your help is very much
appreciated!!! Thanks!


Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)



Private Sub CommandButton1_Click()

Call keybd_event(&H2C, 0, 0, 0)
ActiveSheet.Paste




Dim MyChart As String, MyPicture As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False

MyPicture = Selection.Name

With Selection
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With

UserForm1.TextBox1.Value = PicHeight
UserForm1.TextBox2.Value = PicWidth

Charts.Add
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
Selection.Border.LineStyle = 0
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
With .Shapes(MyChart)
.Width = UserForm1.TextBox2.Value
.Height = UserForm1.TextBox1.Value
End With

.Shapes(MyPicture).Copy

With ActiveChart
.ChartArea.Select
.Paste
End With

.ChartObjects(1).Chart.Export Filename:="C:\MyPic.gif",
FilterName:="gif"
.Shapes(MyChart).Cut
End With

Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default What is wrong with this code? Screen capture and export as image?

Selection.Height and Selection.Width is the height and width of the first
cell in the selection. You need to do something like this

set FirstCell = Selection
set LastCell = Selection.SpecialCells(xlCellTypeLastCell)

PicHeight = (LastCell.Top + LastCell.Height) - FirstCell.Top
PicWidth = (LastCell.Left + LastCell.Widcth) - FirstCell.Left



" wrote:

Fellow programmers,

I have written a code to screencapture my current desktop and paste
it as a chart object -- so that Excel can export what it
screencaptured. The code works -- it's just that the picture is really
tiny... any ideas? Below is my code -- your help is very much
appreciated!!! Thanks!


Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)



Private Sub CommandButton1_Click()

Call keybd_event(&H2C, 0, 0, 0)
ActiveSheet.Paste




Dim MyChart As String, MyPicture As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False

MyPicture = Selection.Name

With Selection
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With

UserForm1.TextBox1.Value = PicHeight
UserForm1.TextBox2.Value = PicWidth

Charts.Add
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
Selection.Border.LineStyle = 0
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
With .Shapes(MyChart)
.Width = UserForm1.TextBox2.Value
.Height = UserForm1.TextBox1.Value
End With

.Shapes(MyPicture).Copy

With ActiveChart
.ChartArea.Select
.Paste
End With

.ChartObjects(1).Chart.Export Filename:="C:\MyPic.gif",
FilterName:="gif"
.Shapes(MyChart).Cut
End With

Application.ScreenUpdating = True

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel screen capture to capture cells and row and column headings jayray Excel Discussion (Misc queries) 5 November 2nd 07 11:01 PM
screen capture [email protected] Excel Programming 1 June 25th 07 11:43 AM
Screen shots capture matt dunbar Excel Programming 2 October 8th 04 03:03 PM
How to capture screen through VBA? Bill Choy[_2_] Excel Programming 3 July 23rd 04 05:00 AM
Export the worksheet background image as an image file - possible? DataFreakFromUtah Excel Programming 2 April 10th 04 04:49 PM


All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"