-
Sep 16th, 2017, 06:14 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Image size in document Word
Hello VBForums
Hello every one
Please ..
I send image from Form to word document with this best code :
Code:
Private Sub Command1_Click()
Dim objWord As New Word.Application
objWord.Documents.Add
Clipboard.Clear
Clipboard.SetData Image1.Picture
objWord.Selection.Paste
Clipboard.Clear
objWord.Visible = True
Set objWord = Nothing
End Sub
But the image is too large in document word .. How do I set and i control the image size in Word document ??
Cordially
MADA
-
Sep 16th, 2017, 07:22 AM
#2
Re: Image size in document Word
Mada
No answer yet, but a question .. what final result are you trying to achieve?
- shrink the image to fit?
- crop the image to fit?
It might help if you could post a screenshot of how the image is currently appearing in the Word doc.
Spoo
-
Sep 16th, 2017, 07:46 AM
#3
Thread Starter
Hyperactive Member
Re: Image size in document Word
Hii Spooman
Thank you very much for help
Please see this image in Form :
And when i send it to word .. see the size is too big
I want the image size in word to be small as in the form
Cordially
MADA
-
Sep 16th, 2017, 08:24 AM
#4
Re: Image size in document Word
The answer to this will not be Visual Basic code. Instead you need to look into the Word Automation Object Model to see what your options might be.
This is not a VB question, it is a Word Automation question. You have posted in the wrong forum.
-
Sep 16th, 2017, 08:28 AM
#5
Re: Image size in document Word
Mada
Thanks for the images, but I'm a little confused.
The Word image is neither shrunk nor cropped. Rather, the aspect ratio has changed.
Indeed, in Word, it kinda makes sense (it's readable), whereas on your Form it's "shrunk" in the horizontal dimension
Be that as it may, the heights appear to be (about) the same, but the widths clearly are not.
Do you want the width in Word to be smaller?
EDIT-1
dile types faster than I do .. and seems to be onto something.
Spoo
-
Sep 16th, 2017, 08:29 AM
#6
Re: Image size in document Word
like dile says....see this: http://software-solutions-online.com...size-pictures/ (Note: Macro in VBA...that's the clue.)
-
Sep 16th, 2017, 08:31 AM
#7
Re: Image size in document Word
The image in word looks correct. The one on the form looks like it has been set to fit the box and as a result has been shrunk and distorted.
You should resize your source image file.
-
Sep 16th, 2017, 08:34 AM
#8
Re: Image size in document Word
Is there an echo in here?
-
Sep 16th, 2017, 09:03 AM
#9
Thread Starter
Hyperactive Member
Re: Image size in document Word
Thank you for all personne
Very nice of you gentelmans
But how to input the word " shape " in code for resize my image please
Cordially
MADA
-
Sep 16th, 2017, 09:28 AM
#10
Re: Image size in document Word
Did you not even LOOK AT that link I posted? Gives you all you need. AND, like dile says, its a VBA question as it relates to MS WORD handling the size, not VB6.
-
Sep 16th, 2017, 09:33 AM
#11
Thread Starter
Hyperactive Member
Re: Image size in document Word
Hiii SamOscarBrown
I looked at this link
but frankly I have not figured out how to take codes from this site and put them in my code in my form
Cordially
MADA
-
Sep 16th, 2017, 11:13 AM
#12
Re: Image size in document Word
Not so much a VBA question as a Word Object Model question.
The approach required should be the same in VB, VBA, VBScript, JScript, Delphi, ActivePerl, etc. Maybe Microsoft should have called this "Puppet Strings" instead of "Automation." The issue isn't about the puppeteer but the puppet (Word).
-
Sep 16th, 2017, 11:23 AM
#13
Re: Image size in document Word
I still say you should resize the source image to the size you want it to be then add it.
Adding a larger image and scaling it down just wastes memory, disk space and cpu cycles.
-
Sep 16th, 2017, 11:39 AM
#14
Thread Starter
Hyperactive Member
Re: Image size in document Word
Thank you masters for help
Thank you very for all personne
it seems that there is no desired result
I will leave the subject of the Word and picture..
Cordially
MADA
-
Sep 16th, 2017, 12:26 PM
#15
Re: Image size in document Word
Well...you give up too easily! Often times I try and try and try, and then try again, to solve a programming problem. I do most of it by myself (although I have had plenty of help from members of this forum). It is through trial and error (and constant research and reading) that has gotten me able to be a fair part-time developer. It appears you, however, copy-paste code from this forum without really understanding what it does...hence, you never really learn...and when you keep piece-mealing it all together, you'll run into more problems than you'll ever desire.
But, I DID take the time to work though it myself just for an exercise, and came up with this. I used the code I showed you earlier and added a piece that looks at the inlineshapes in the Word Document, and sets their sizes (I only used one picture) to 50% of their heights and widths.
Code:
Option ExplicitDim sFile As String
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objDocContent As Word.Range
Dim oTable As Word.Table
Private Sub Form_Load()
Text5.Text = Date
End Sub
Private Sub Command1_Click()
Dim i As Long
sFile = App.Path & "\Documentary.doc"
Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open(sFile)
Set oTable = objDoc.Tables.Add(objDoc.Range(0, 0), 5, 5)
objWord.Documents(objDoc).Activate
Set objDocContent = objWord.ActiveDocument.Content
With objDoc
.Tables.Item(1).Cell(1, 1).Range.Text = Text1.Text
.Tables.Item(1).Cell(1, 2).Range.InlineShapes.AddPicture (App.Path & "\mypicture.jpg")
.Tables.Item(1).Cell(1, 3).Range.Text = Text3.Text
With objWord.ActiveDocument
For i = 1 To .InlineShapes.Count
With .InlineShapes(i)
.ScaleHeight = 50 'scale it to whatever size you see fit
.ScaleWidth = 50
End With
Next i
End With
End With
objDoc.SaveAs FileName:=App.Path & "\Documentary_" & Format(Text5.Text, "DD_MMM_YYYY") & ".doc"
objWord.Documents.Close
objWord.Quit
Set objWord = Nothing
MsgBox "DONE" 'Let the User know it is done
End Sub
-
Sep 16th, 2017, 01:54 PM
#16
Thread Starter
Hyperactive Member
Re: Image size in document Word
Hiii SamOscarBrown
Thank you enormously master
You have exactly read what I wanted to see and have
Thanks for your super and extra code .. your kindness and well followed by this subject
Perfectly resolved
Cordially
MADA
-
Sep 16th, 2017, 02:26 PM
#17
Re: [RESOLVED] Image size in document Word
It is not perfect (far from it), but it might get you by. It has some lines in there that are not the optimum (like table columns/rows, etc). Suggest you get a book and read it...one that talks specifically about Using MS Word with VB6 (or even VB.NET...the concept I am sure is similar, syntax may be different...don't know for sure, as I am only a very beginner in Visual Studio.Net.)
-
Sep 16th, 2017, 04:00 PM
#18
Re: [RESOLVED] Image size in document Word
Looks like y'all have this one all worked out. But this is something I do all the time. Here's an example of a line of code where I do it:
Code:
Set shp = doc.shapes.AddPicture(sBmpSpec, False, True, dLeft, dTop, dWidth, dHeight, vAnchor)
Now, I use late-binding for all my automation, so shp is just declared as an object. But, if you get into the Word VBA Help system, it'll tell you how to do all of this stuff.
You could also change the size after it was added, but, in that line above, I just set the size when it's inserted into the Word document.
I see absolutely no reason you'd need to resize the picture on the VB6 side. Word is perfectly capable (through automation like the above) to make it any size you like.
Good Luck,
Elroy
EDIT1: Just as a further FYI, that vAnchor is basically where the dLeft, dTop, dWidth, dHeight are relative to. You can omit it and the picture is positioned relative to the page. In my Word templates, I put named objects in them that say where I want the top-left edges of my pictures (and that's where vAnchor comes from). That just makes things easier, but you don't really need those.
EDIT2: Just my humble opinion: If we're actually talking about VBA code, I'd have to agree that this is in the wrong forum. However, if we're talking about automating Word from VB6, I think it's in an ideal forum.
Last edited by Elroy; Sep 16th, 2017 at 04:25 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Sep 16th, 2017, 05:31 PM
#19
Re: [RESOLVED] Image size in document Word
Very Good!
MADA BLACK...take Elroy's advice...ignore mine. I only 'trialed and errorred' until I got it 'to work'...Elroy knows what he's doing (obviously!).
Sammi
-
Sep 16th, 2017, 07:45 PM
#20
Re: [RESOLVED] Image size in document Word
hahaha, well, if we're talking about using assembly thunks to control the IDE while in development mode, I can get lost pretty quickly.
Also, a LONG time ago, I tried looking at Crystal Reports for reporting purposes, but threw up my hands. That's why you never see me participate in any of those threads.
However, I do use Word and Excel (from VB6) to get almost all of my reporting done. I just love designing a report in Word, and then saving it as a DOT (or DOTX), and then using that to generate my reports. I'm not the be-all-end-all of Word automation, but I'm well above average in that area. I keep a copy of the Word VBA help on my desktop.
Sam, you have a wonderful Saturday.
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Sep 16th, 2017, 10:20 PM
#21
Re: [RESOLVED] Image size in document Word
Originally Posted by Elroy
Also, a LONG time ago, I tried looking at Crystal Reports for reporting purposes, but threw up my hands. That's why you never see me participate in any of those threads.
I used Crystal for a while back in VB5 at work. I learned to hate it rather quickly, in fact none of the coders there really liked it. We went searching for something else, looked at several different tools but ended up using Active Reports which IMO is far better for a VB coder than anything else I have saw.
-
Sep 17th, 2017, 11:16 AM
#22
Re: [RESOLVED] Image size in document Word
Back in the day, I actually wound up developing rather extensive routines that just used the printer object from VB6. I still occasionally use them, but I now use Word and Excel templates for 99% of my reporting.
Truth be told, MS-Access has one of the best report-writers in it I've ever seen, especially when dealing with records of data (even when hierarchical/relational). The only downside is that you must have MS-Access on the machine (which isn't a given), and they're not terribly easy to "get at" from VB6. It can be done, just not easily.
It'd be really nice if someone would develop an OCX that has all the features of the MS-Access report writer, with all the keep-together, header-footer, labels, insert pictures, good page breaking, etc stuff. But that's quite the project. Maybe Active Reports does that. I've never looked at it.
These days, I don't really have many situations where I'm dumping a large number of rows for a report, so it's a bit moot for me. And, in the few cases where I am doing that, I just use Excel.
Take Care,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
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
|