|
-
Nov 30th, 2011, 01:25 AM
#1
Error when adding a picture
Hi guys 
This is the code that worked without any problems in Word2007:
Code:
Dim pp As Shape
pp = ActiveDocument.Bookmarks.Item("\StartOfDoc").Range.InlineShapes.AddPicture(FileName:="c:\abc.jpg", LinkToFile:=False, SaveWithDocument:=True).ConvertToShape
But when I tried in Word2003, it shows an error:
Code:
Object variable or with variable not set
Any ideas ?
Thanks
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 30th, 2011, 02:40 AM
#2
Re: Error when adding a picture
i would imagine that as shape is an object, you would need the SET keyword
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 30th, 2011, 03:01 AM
#3
Re: Error when adding a picture
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 30th, 2011, 03:44 AM
#4
Re: Error when adding a picture
you may need to convert the inlineshape to a shape, as inlineshapes can not be positioned absolutely, as they move in relation to text insertions etc
So, in Word2007, it uses the .Net style and in Word2003, it is VB6 style ?
as i still use office 2000 i can not compare what goes on in 2007, but most of my code appears to work for posters using 2007 and 2010
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 30th, 2011, 04:44 AM
#5
Re: Error when adding a picture
 Originally Posted by westconn1
you may need to convert the inlineshape to a shape, as inlineshapes can not be positioned absolutely, as they move in relation to text insertions etc
I am already doing it using the ConvertToShape() method. (See the end of that line)
 Originally Posted by westconn1
as i still use office 2000 i can not compare what goes on in 2007, but most of my code appears to work for posters using 2007 and 2010
hmm.. But in 2010, I used without the set keyword and no error was shown. But in 2003, it has to be used with the Set keyword. This looks like the same thing in VB.Net and VB6 for assigning objects. Isn't it ?
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 30th, 2011, 05:08 AM
#6
Re: Error when adding a picture
I am already doing it using the ConvertToShape() method. (See the end of that line)
i did not scroll that far
did you test if pp is a shape or inlineshape?
This looks like the same thing in VB.Net and VB6 for assigning objects. Isn't it ?
i guess
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 30th, 2011, 05:10 AM
#7
Re: Error when adding a picture
 Originally Posted by westconn1
did you test if pp is a shape or inlineshape?
hmm.. How to do that ?
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 30th, 2011, 06:16 AM
#8
Re: Error when adding a picture
no need, as it is declared a shape, it has to be
in that case i do not know why it will not stay in position, check the anchors are as expected, they may default differently to word 2007 +
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 30th, 2011, 11:19 AM
#9
Re: Error when adding a picture
 Originally Posted by westconn1
no need, as it is declared a shape, it has to be
in that case i do not know why it will not stay in position, check the anchors are as expected, they may default differently to word 2007 +
Ok. Which anchor are you talking about ? The "\StartOfDoc" ? And how to do the checking ?
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Nov 30th, 2011, 03:23 PM
#10
Re: Error when adding a picture
from msdn
Anchor Property
Returns a Range object that represents the anchoring range for the specified shape or shape range. Read-only.
Remarks
All Shape objects are anchored to a range of text but can be positioned anywhere on the page that contains the anchor. If you specify the anchoring range when you create a shape, the anchor is positioned at the beginning of the first paragraph that contains the anchoring range. If you don't specify the anchoring range, the anchoring range is selected automatically and the shape is positioned relative to the top and left edges of the page.
The shape will always remain on the same page as its anchor. If the LockAnchor property for the shape is set to True, you cannot drag the anchor from its position on the page.
If you use this property on a ShapeRange object that contains more than one shape, an error occurs.
will move the picture to the top of the current page
if you can find which page it is on, you can move it to the page you wish
Last edited by westconn1; Nov 30th, 2011 at 03:34 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|