[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert image macro

Posted on 2011-10-09
11
Medium Priority
?
248 Views
Last Modified: 2012-05-12
Hello,

I have a macro that inserts an image into a document at an absolute position. This works really well.modified it so if the document is protected it unprotects and then add the image.
I am able to create docs, add form fields, protect doc and then use the macro to insert the image. A number of pre-existing documents crash for some reason when I try and run the macro.
Can you please have a look and try and see why this doc attached crashes when i try and run the macro - code below Arrears-1.dot
Sub InsertPictureShape()
Dim sh As Shape
With ActiveDocument
    ProtectType = .ProtectionType
    If Not (ProtectType = wdNoProtection) Then
      .Unprotect
    End If
  Set sh = .Shapes.AddPicture("C:\image\sbs.png", False, True, , , , Selection.Paragraphs(1).Range)
    sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
    sh.RelativeVerticalPosition = wdRelativeVerticalPositionTopMarginArea
    sh.Top = CentimetersToPoints(0.8)
    sh.Left = CentimetersToPoints(12.2)
    
    If Not (ProtectType = wdNoProtection) Then
      .Protect ProtectType, True
    End If
    End With
    
End Sub

Open in new window

0
Comment
Question by:sbsbats
  • 7
  • 3
11 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 36939623
which line? whats the error message?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36939632
I created a new document form the template under Word 2007, and the macro worked without a problem.
0
 

Author Comment

by:sbsbats
ID: 36939634
LIne 8
"One of the values passed to this method or property is out of range"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:sbsbats
ID: 36939647
HI Graham,

Haven't tried 2007 - doc created in 2003 and being used in 2010.
Will try converting and let you know
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36939650
I can reproduce that problem if I open the template directly (instead of creating a new document from it).
0
 

Author Comment

by:sbsbats
ID: 36939655
Thats strange - Let me test again but I open the old fashion way - file - new- templates.
0
 

Author Comment

by:sbsbats
ID: 36939658
Nope - it is still crashing when I try and run the doc - am double clicking and creatig the .doc for sure.
Do you have a copy of 2010 to test?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1500 total points
ID: 36939674
Sorry. No 2010. 2007 ate enough into my pension.

I have seen the symptom before. Somewhere, internally, a value is actually out of range, but it isn't needed anyway.

Apart from  creating a new document from the template in the way that I said, I can also create a new document by copying the open document and pasting to a new blank one. Either way, the new document doesn't have the problem.
0
 

Author Comment

by:sbsbats
ID: 36939888
Hi Graham,

Not really an option considering how many doc's I want to use this with - makes sense what you say about error as image does get placed on doc, just with the error - also it is placed on the left hand side of the page where the curser would start from instead of its absolute position.
0
 

Author Comment

by:sbsbats
ID: 36940026
Looks like I may need some help from an Office 2010 expert - the problem seems to be related to the fact its a template and not a doc.
When I re-create this doc and save it as a doc and run it no problems - when i save it as a 97-2003 template it causes this crash.
Any help from an Office expert please?
0
 

Author Closing Comment

by:sbsbats
ID: 36945473
compatibility issue alright
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Suggested Courses

872 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