Solved

Use vb6 program to change size of image in an excel worksheet

Posted on 2012-03-09
2
656 Views
Last Modified: 2012-03-10
I'm using the following code to insert an image into an Excel 2007 Worksheet utilizing VB6 (not a macro).

Const msoFalse = 1
Sub positionpicture()
Dim p As Picture
Dim wkb As Workbook
Dim wks As Worksheet
Dim pBeginX As Single 'relative to upper-left corner of document
Dim pBeginY As Single 'relative to upper-left corner of document
Dim pEndX As Single 'relative to upper-left corner of document
Dim pEndY As Single 'relative to upper-left corner of document
Dim InchToPoint As Single

    Set wkb = ActiveWorkbook
    Set wks = Sheets("Sheet1")
   
    '18 points per .25 inches
    InchToPoint = 18 / 0.25
   
    '2 inches from the left, 6 inches down
    pBeginX = 1 * InchToPoint
    pBeginY = 1 * InchToPoint
    pEndX = 11 * InchToPoint
    pEndY = 11 * InchToPoint
   
    Set p = wks.Pictures.Insert(App.Path & "\" & "tlsig.jpg")

    'keep or lock the aspect ratio
    p.ShapeRange.LockAspectRatio = msoFalse
    'Top left corner
    p.Locked = False
    p.Left = pBeginX
    p.Top = pBeginY
End Sub

How can I resize the image and position it? The image is not responding to the above attempt to position it nor is it responding to the following code:
p.left = wks.range("A39").left
p.top = wks.range("A39").top

Thanks.
0
Comment
Question by:tlengnick
  • 2
2 Comments
 

Accepted Solution

by:
tlengnick earned 0 total points
ID: 37705324
I got it:

Sub PositionPicture3()

Dim Excel_App As Excel.Application
Const msoFalse = 1

With Excel_App
  ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Select

    With Selection
        .ShapeRange.LockAspectRatio = msoFalse
        .ShapeRange.Top = 660
        .ShapeRange.Left = 10
        .ShapeRange.Width = 200
        .Placement = xlMoveAndSize
    End With
End With
0
 

Author Closing Comment

by:tlengnick
ID: 37705327
Found the answer online... figured I'd add it to knowledgebase.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now