Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default insert picture in a range

Hi Dave,
Using this macro, how can I insert the picture in a range say- A36:G44,
I have been fooling around with the Set myRng = ActiveCell line but
can't seem to get the proper syntax
Dave


2. Dave Peterson
Nov 14 2005, 5:27 am show options
Newsgroups: microsoft.public.excel
From: Dave Peterson - Find messages by this
author
Date: Mon, 14 Nov 2005 06:27:16 -0600
Local: Mon, Nov 14 2005 5:27 am
Subject: insert picture
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Maybe you could give the user a macro to insert the picture. Then
you'll have
more control over what happens:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting
path."
End Sub
Sub testme01()

Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String

myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"

On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0

myPictureName = Application.GetOpenFilename _
(filefilter:="Picture
Files,*.jpg;*.bmp;*.tif;*.gif")

ChDirNet myCurFolder

If myPictureName = False Then
Exit Sub 'user hit cancel
End If

Set myRng = ActiveCell
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default insert picture in a range

I copied your code and fixed the line wrap problems and it worked perfectly for
me.

It put the picture right over the activecell.

Did you mean the multiple cells (maybe the current selection???). If you did,
then try this:

Set myRng = ActiveCell
becomes
Set myRng = selection.areas(1)

(Just in case you have multiple areas currently selected.)



damorrison wrote:

Hi Dave,
Using this macro, how can I insert the picture in a range say- A36:G44,
I have been fooling around with the Set myRng = ActiveCell line but
can't seem to get the proper syntax
Dave

2. Dave Peterson
Nov 14 2005, 5:27 am show options
Newsgroups: microsoft.public.excel
From: Dave Peterson - Find messages by this
author
Date: Mon, 14 Nov 2005 06:27:16 -0600
Local: Mon, Nov 14 2005 5:27 am
Subject: insert picture
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Maybe you could give the user a macro to insert the picture. Then
you'll have
more control over what happens:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting
path."
End Sub
Sub testme01()

Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String

myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"

On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0

myPictureName = Application.GetOpenFilename _
(filefilter:="Picture
Files,*.jpg;*.bmp;*.tif;*.gif")

ChDirNet myCurFolder

If myPictureName = False Then
Exit Sub 'user hit cancel
End If

Set myRng = ActiveCell
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default insert picture in a range

That's it!
Thanks again
Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default insert picture in a range

Hello mr. Peterson,

I just copied your macro and everything goes allright, untill one of the
last lines: lReturn=SetCurrent DirectoryA (szPath). The error says: 'Can't
find the directory'.
What can I do about it.

Thank you anyway.

Mathieu Borms
"Dave Peterson" wrote:

I copied your code and fixed the line wrap problems and it worked perfectly for
me.

It put the picture right over the activecell.

Did you mean the multiple cells (maybe the current selection???). If you did,
then try this:

Set myRng = ActiveCell
becomes
Set myRng = selection.areas(1)

(Just in case you have multiple areas currently selected.)



damorrison wrote:

Hi Dave,
Using this macro, how can I insert the picture in a range say- A36:G44,
I have been fooling around with the Set myRng = ActiveCell line but
can't seem to get the proper syntax
Dave

2. Dave Peterson
Nov 14 2005, 5:27 am show options
Newsgroups: microsoft.public.excel
From: Dave Peterson - Find messages by this
author
Date: Mon, 14 Nov 2005 06:27:16 -0600
Local: Mon, Nov 14 2005 5:27 am
Subject: insert picture
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Maybe you could give the user a macro to insert the picture. Then
you'll have
more control over what happens:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting
path."
End Sub
Sub testme01()

Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String

myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"

On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0

myPictureName = Application.GetOpenFilename _
(filefilter:="Picture
Files,*.jpg;*.bmp;*.tif;*.gif")

ChDirNet myCurFolder

If myPictureName = False Then
Exit Sub 'user hit cancel
End If

Set myRng = ActiveCell
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize

End Sub


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default insert picture in a range

Hello Mr. Peterson,

I just copied your macro, but I have a problem in one of the last lines:

"Dave Peterson" wrote:

I copied your code and fixed the line wrap problems and it worked perfectly for
me.

It put the picture right over the activecell.

Did you mean the multiple cells (maybe the current selection???). If you did,
then try this:

Set myRng = ActiveCell
becomes
Set myRng = selection.areas(1)

(Just in case you have multiple areas currently selected.)



damorrison wrote:

Hi Dave,
Using this macro, how can I insert the picture in a range say- A36:G44,
I have been fooling around with the Set myRng = ActiveCell line but
can't seem to get the proper syntax
Dave

2. Dave Peterson
Nov 14 2005, 5:27 am show options
Newsgroups: microsoft.public.excel
From: Dave Peterson - Find messages by this
author
Date: Mon, 14 Nov 2005 06:27:16 -0600
Local: Mon, Nov 14 2005 5:27 am
Subject: insert picture
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Maybe you could give the user a macro to insert the picture. Then
you'll have
more control over what happens:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting
path."
End Sub
Sub testme01()

Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String

myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"

On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0

myPictureName = Application.GetOpenFilename _
(filefilter:="Picture
Files,*.jpg;*.bmp;*.tif;*.gif")

ChDirNet myCurFolder

If myPictureName = False Then
Exit Sub 'user hit cancel
End If

Set myRng = ActiveCell
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize

End Sub


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default insert picture in a range



"mathieu" wrote:

Hello mr. Peterson,

I just copied your macro and everything goes allright, untill one of the
last lines: lReturn=SetCurrent DirectoryA (szPath). The error says: 'Can't
find the directory'.
What can I do about it.

Thank you anyway.

Mathieu Borms

Problem solved. Thanx

"Dave Peterson" wrote:

I copied your code and fixed the line wrap problems and it worked perfectly for
me.

It put the picture right over the activecell.

Did you mean the multiple cells (maybe the current selection???). If you did,
then try this:

Set myRng = ActiveCell
becomes
Set myRng = selection.areas(1)

(Just in case you have multiple areas currently selected.)



damorrison wrote:

Hi Dave,
Using this macro, how can I insert the picture in a range say- A36:G44,
I have been fooling around with the Set myRng = ActiveCell line but
can't seem to get the proper syntax
Dave

2. Dave Peterson
Nov 14 2005, 5:27 am show options
Newsgroups: microsoft.public.excel
From: Dave Peterson - Find messages by this
author
Date: Mon, 14 Nov 2005 06:27:16 -0600
Local: Mon, Nov 14 2005 5:27 am
Subject: insert picture
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

Maybe you could give the user a macro to insert the picture. Then
you'll have
more control over what happens:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting
path."
End Sub
Sub testme01()

Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String

myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"

On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0

myPictureName = Application.GetOpenFilename _
(filefilter:="Picture
Files,*.jpg;*.bmp;*.tif;*.gif")

ChDirNet myCurFolder

If myPictureName = False Then
Exit Sub 'user hit cancel
End If

Set myRng = ActiveCell
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize

End Sub


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default insert picture in a range

That's stange, because the code is supposed to let you find the
directory, there are two codes for this you may be just having copy and
paste problems, here it is again

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then
Err.Raise vbObjectError + 1, "Error setting path."
End If
End Sub
Sub testme01()


Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String


myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"


On Error Resume Next
ChDirNet myNewFolder
If Err.Number < 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0
myPictureName = Application.GetOpenFilename _
(filefilter:="Picture
Files,*.jpg;*.bmp;*.tif;*.gif")


ChDirNet myCurFolder


If myPictureName = False Then
Exit Sub 'user hit cancel
End If


Set myRng = ActiveCell
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize


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
how do I insert picture into cell so vlookup can return picture? ah Excel Worksheet Functions 1 May 1st 07 04:38 AM
insert a picture in to a comment but picture not save on hard disk Pablo Excel Discussion (Misc queries) 0 February 21st 07 03:48 PM
insert picture to a specfic range of cells CORY Excel Discussion (Misc queries) 8 February 3rd 06 05:50 PM
How to insert a picture Vance Porfirio Excel Discussion (Misc queries) 0 January 3rd 06 05:52 PM
Insert Picture to Excel to specified range Budiono[_2_] Excel Programming 5 October 13th 03 04:21 AM


All times are GMT +1. The time now is 08:55 AM.

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

About Us

"It's about Microsoft Excel"