Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Put a picture in a text box without selecting it?

Can this be done without selecting the text box? I am using it to put a
picture in a text box, the picture number is in cell G1. Or is there a
better way?

Using Excel 2003

Thanks



Sub ShowPictures()



ActiveSheet.Shapes("Text Box 21").Select

Selection.Characters.Text = ""

With Selection.Font

.Name = "Arial"

.FontStyle = "Regular"

.Size = 10

.Strikethrough = False

.Superscript = False

.Subscript = False

.OutlineFont = False

.Shadow = False

.Underline = xlUnderlineStyleNone

.ColorIndex = xlAutomatic



End With

Selection.ShapeRange.Fill.Transparency = 0#

Selection.ShapeRange.Line.Weight = 0.75

Selection.ShapeRange.Line.DashStyle = msoLineSolid

Selection.ShapeRange.Line.Style = msoLineSingle

Selection.ShapeRange.Line.Transparency = 0#

Selection.ShapeRange.Line.Visible = msoTrue

Selection.ShapeRange.Line.ForeColor.SchemeColor = 64

Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

Selection.ShapeRange.Fill.Visible = msoTrue

Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)

Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)



On Error GoTo NoPic



Selection.ShapeRange.Fill.UserPicture _

Application.DefaultFilePath & "\My Pictures\Carousels" & "\" &
Range("G1").Value & ".jpg"



On Error GoTo 0

Exit Sub



NoPic:

MsgBox Prompt:="No Picture Available", _

Title:="Error Retrieving Picture", _

Buttons:=vbOKOnly

On Error GoTo 0



End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Put a picture in a text box without selecting it?

This worked ok for me.

Just a warning...
if that number in G1 that is the name of the file, you may have to format it to
show any leading 0's.

You may need to use something like:
& format(.range("g1").value, "00000") & ".jpg"

Option Explicit
Sub ShowPictures()

Dim TBox As TextBox
Dim myFileName As String
Dim TestStr As String

With ActiveSheet
Set TBox = .TextBoxes("text box 21")
myFileName = Application.DefaultFilePath _
& "\My Pictures\Carousels" & "\" _
& .Range("G1").Value & ".jpg"
End With

With TBox
.Characters.Text = ""
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

With .ShapeRange
.Fill.Transparency = 0#
.Line.Weight = 0.75
.Line.DashStyle = msoLineSolid
.Line.Style = msoLineSingle
.Line.Transparency = 0#
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = 64
.Line.BackColor.RGB = RGB(255, 255, 255)
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.BackColor.RGB = RGB(255, 255, 255)

TestStr = ""
On Error Resume Next
TestStr = Dir(myFileName)
On Error GoTo 0

If TestStr = "" Then
MsgBox Prompt:="No Picture Available", _
Title:="Error Retrieving Picture", _
Buttons:=vbOKOnly
Else
.Fill.UserPicture picturefile:=myFileName
End If
End With
End With

End Sub

Paul B wrote:

Can this be done without selecting the text box? I am using it to put a
picture in a text box, the picture number is in cell G1. Or is there a
better way?

Using Excel 2003

Thanks

Sub ShowPictures()

ActiveSheet.Shapes("Text Box 21").Select

Selection.Characters.Text = ""

With Selection.Font

.Name = "Arial"

.FontStyle = "Regular"

.Size = 10

.Strikethrough = False

.Superscript = False

.Subscript = False

.OutlineFont = False

.Shadow = False

.Underline = xlUnderlineStyleNone

.ColorIndex = xlAutomatic

End With

Selection.ShapeRange.Fill.Transparency = 0#

Selection.ShapeRange.Line.Weight = 0.75

Selection.ShapeRange.Line.DashStyle = msoLineSolid

Selection.ShapeRange.Line.Style = msoLineSingle

Selection.ShapeRange.Line.Transparency = 0#

Selection.ShapeRange.Line.Visible = msoTrue

Selection.ShapeRange.Line.ForeColor.SchemeColor = 64

Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

Selection.ShapeRange.Fill.Visible = msoTrue

Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)

Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)

On Error GoTo NoPic

Selection.ShapeRange.Fill.UserPicture _

Application.DefaultFilePath & "\My Pictures\Carousels" & "\" &
Range("G1").Value & ".jpg"

On Error GoTo 0

Exit Sub

NoPic:

MsgBox Prompt:="No Picture Available", _

Title:="Error Retrieving Picture", _

Buttons:=vbOKOnly

On Error GoTo 0

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Put a picture in a text box without selecting it?

Dave, thanks for this one also, works fine

"Dave Peterson" wrote in message
...
This worked ok for me.

Just a warning...
if that number in G1 that is the name of the file, you may have to format
it to
show any leading 0's.

You may need to use something like:
& format(.range("g1").value, "00000") & ".jpg"

Option Explicit
Sub ShowPictures()

Dim TBox As TextBox
Dim myFileName As String
Dim TestStr As String

With ActiveSheet
Set TBox = .TextBoxes("text box 21")
myFileName = Application.DefaultFilePath _
& "\My Pictures\Carousels" & "\" _
& .Range("G1").Value & ".jpg"
End With

With TBox
.Characters.Text = ""
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

With .ShapeRange
.Fill.Transparency = 0#
.Line.Weight = 0.75
.Line.DashStyle = msoLineSolid
.Line.Style = msoLineSingle
.Line.Transparency = 0#
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = 64
.Line.BackColor.RGB = RGB(255, 255, 255)
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.BackColor.RGB = RGB(255, 255, 255)

TestStr = ""
On Error Resume Next
TestStr = Dir(myFileName)
On Error GoTo 0

If TestStr = "" Then
MsgBox Prompt:="No Picture Available", _
Title:="Error Retrieving Picture", _
Buttons:=vbOKOnly
Else
.Fill.UserPicture picturefile:=myFileName
End If
End With
End With

End Sub

Paul B wrote:

Can this be done without selecting the text box? I am using it to put a
picture in a text box, the picture number is in cell G1. Or is there a
better way?

Using Excel 2003

Thanks

Sub ShowPictures()

ActiveSheet.Shapes("Text Box 21").Select

Selection.Characters.Text = ""

With Selection.Font

.Name = "Arial"

.FontStyle = "Regular"

.Size = 10

.Strikethrough = False

.Superscript = False

.Subscript = False

.OutlineFont = False

.Shadow = False

.Underline = xlUnderlineStyleNone

.ColorIndex = xlAutomatic

End With

Selection.ShapeRange.Fill.Transparency = 0#

Selection.ShapeRange.Line.Weight = 0.75

Selection.ShapeRange.Line.DashStyle = msoLineSolid

Selection.ShapeRange.Line.Style = msoLineSingle

Selection.ShapeRange.Line.Transparency = 0#

Selection.ShapeRange.Line.Visible = msoTrue

Selection.ShapeRange.Line.ForeColor.SchemeColor = 64

Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

Selection.ShapeRange.Fill.Visible = msoTrue

Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)

Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)

On Error GoTo NoPic

Selection.ShapeRange.Fill.UserPicture _

Application.DefaultFilePath & "\My Pictures\Carousels" & "\" &
Range("G1").Value & ".jpg"

On Error GoTo 0

Exit Sub

NoPic:

MsgBox Prompt:="No Picture Available", _

Title:="Error Retrieving Picture", _

Buttons:=vbOKOnly

On Error GoTo 0

End Sub


--

Dave Peterson



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
Selecting and cutting unknown picture numbers from a specifc range of cells [email protected] Excel Programming 3 October 29th 07 09:09 PM
Combining a Text or picture into another picture avi Excel Programming 1 April 8th 07 01:04 AM
how to make a picture pop-up when selecting a cell? tendercare New Users to Excel 1 September 6th 05 12:47 PM
Background Picture OR text over a picture greg Excel Discussion (Misc queries) 1 March 30th 05 12:31 AM
selecting a picture within a chart via a macro Walshy[_3_] Excel Programming 1 October 21st 04 10:32 AM


All times are GMT +1. The time now is 08:02 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"