PDA

View Full Version : Help in understanding Range and additional frames in Word



Viewbasic
10-21-2008, 08:59 PM
Could someone explain to me how the range functions work in word applications and how to actually implement it into an actual code? And Could you also explain how to make a multi-user frame functional?

So far in the current code I am working in, I have been able to add frame to my userform, but I am unable to make the additional frame invisble when I run my form.

Here is a sample of what I have for as far as the frames go:

Private Sub Userform_Initialize()
fraClient.Visible = True
fraProduct.Visible = False
End Sub

although I have made the sub initialize, the second frame still is visible.
I'm not sure if I put the frame in wrong or I have an error in my code. (The rest of the code places my text into the actual application)

Sorry for the heavy load. :help

Thanks for helping

lucas
10-21-2008, 09:11 PM
Hi viewbasic,
as for the userform and frame, your code works for me. What version of Office are you using?


Try my attached example

lucas
10-21-2008, 09:18 PM
From the help file:
Range Returns a Range object that represents the portion of a document that's contained in the specified object.

A few examples from the help file. Look up range in the vbe for more info:

This example applies the Heading 1 style to the first paragraph in the active document.
ActiveDocument.Paragraphs(1).Range.Style = wdStyleHeading1

This example copies the first row in table one.
If ActiveDocument.Tables.Count >= 1 Then _
ActiveDocument.Tables(1).Rows(1).Range.Copy

This example changes the text of the first comment in the document.
With ActiveDocument.Comments(1).Range
.Delete
.InsertBefore "new comment text"
End With

This example inserts text at the end of section one.
Set myRange = ActiveDocument.Sections(1).Range
With myRange
.MoveEnd Unit:=wdCharacter, Count:=-1
.Collapse Direction:=wdCollapseEnd
.InsertParagraphAfter
.InsertAfter "End of section"
End With

Viewbasic
10-21-2008, 09:34 PM
Wow thanks alot that cleared up part of the problem. :thumb
I also looked at yours and since its like mine, I dont understand why it does not work
I would show it to you but..
( I don't know how to attach the file)

Viewbasic
10-21-2008, 09:38 PM
Wait I found it

Viewbasic
10-21-2008, 09:39 PM
its not finished

lucas
10-21-2008, 09:42 PM
to post your file go to post reply at the bottom left of the last post and after you post your message, scroll down and look for "manage attachments"

I'm guessing you have a name problem. One of them is spelled wrong. Click on the frames and check their properties ......look for name at the top of the properties box.

to view the properties box go to view-properties window.

lucas
10-21-2008, 09:44 PM
You should use Option explicit at the top of your module as in my example. It will give you good hints on errors you receive.

lucas
10-21-2008, 10:04 PM
You are trying to use the main part of the form as your client form.

comment or delete this line in the initialize procedure and try it again.


fraClient.Visible = True



I moved some things around and commented a couple of lines of your code to get it to work.......how are you going to use the other frame?

attached is your document with some changes.

Viewbasic
10-21-2008, 10:13 PM
What I want to happen in this program is that in the first frame, or the actual client userform ,the client's name and the company name is inputed onto the worksheet. Then this first frame is hidden and then, frame two, the product frame, this frame becomes visible and allows the user to input his or her product quantity and name

lucas
10-21-2008, 10:17 PM
You will have to add another frame as I did in my first example.

There are lots of ways to do this. I don't understand why you need two frames and if you did why not just use two userforms and have the second open when the first closes......

I suggest you read up on bookmarks too so that if you decide to use this as a template then your data will have a specific place in the document to be located when you hit the ok button.

Viewbasic
10-21-2008, 10:22 PM
I would have to agree with using two seperate userforms or even combining the form into one. However, my client knows a little about VBA and insists I use the frame system. My hands are tied.....

What is an alternative in programing frames, do you know?

lucas
10-21-2008, 10:35 PM
See if this helps. I left coding the second ok button and the rest for you to work on but I think you can see how this might work for your purpose.

Viewbasic
10-21-2008, 10:41 PM
Ok thank you I can definatnly work with this,

however I have one last question. Why was it giving me a error msg that said "this function can not be done, this code might not even be in visible basic" (paraphrased) this appeared when I placed my fraClient= true and fraProduct = false together.

Viewbasic
10-21-2008, 10:43 PM
were my variables undefiend?

lucas
10-21-2008, 10:52 PM
You were not using two frames. You were using one frame and you had renamed the userform itself to fraClient.


I just added another frame and put those controls into it and named it fraClient

lucas
10-21-2008, 10:57 PM
go back and download the first file that you posted and when you look at the properties for fraClient after you click on it you will see that is is a userform not a frame.

Viewbasic
10-21-2008, 11:01 PM
:omg2: he he I see....

Well thanks for your help.

you have a good night

lucas
10-21-2008, 11:05 PM
You're welcome.

You can mark your own thread solved if you have your answers. Use the thread tools at the top of the page.