J
Jason Logue
Hi, I am currently working on a complex macro project for
a client that involves a few layers of userforms and
windows. The main four userforms go with each page of
this template. Just fill in or check the textboxes and
click OK to enter the text. There is one userform that
requires they access outside bookmarked documentation. At
first I tried to set it up where they access one large
manual with many bookmarks, but I realized it would be
easier to split each chapter into its own document. So
right now they click a button on the 3rd Userform and it
performs the following macro:
Sub CommandButton1_Click()
Chapters1.Show
End Sub
This shows another window with a button for each chapter,
which is to say, each document. The client currently uses
a green screen app, punches in a few numbers 1.1 (Chapter
1 and Section 1) to retrieve that text. This seemed to be
the easiest way for me to approach this while making it
easy to use. After they access the Chapters window, they
would click on 1 to access Chapter 1, and the following
code is displayed:
Private Sub CommandButton1_Click()
Chapters1.Hide (this hides the chapter window)
Chapter1a.Show (this shows a listing of buttons for each
section in the chapter 1.1., 1.2, 1.3, and so on)
End Sub
When they choose their section, this will enter text in
the Userform 3 so they can edit or add information to it
and then click OK when doing this for each textbox that
requires this.
The code for this is as follows:
Sub CommandButton1_Click()
Dim i As Integer, source As Document
Set source = Documents.Open("C:\Documents and
Settings\Logue\My Documents\Allied
Title\exceptions\chapterone.doc")
For i = 1 To source.Bookmarks.Count
Userform3.TextBox8.Text = source.Bookmarks(1).Range
- This selects the first bookmark in chapter one. and
inserts the info in Textbox8.
Next i
Documents("C:\Documents and Settings\Logue\My
Documents\Allied Title\exceptions\Chapterone.doc").Close
SaveChanges = False
Chapter1a.Hide
End Sub
Okay, I copy and pasted the code above for each section,
and there are a lot of sections. That's not a big deal
because all I had to do was increase the bookmark amount
each time. The problem is there were three other buttons
I need to access the chapters and sections from, so as you
see above I have Chapter1a, I also created a Chapter1b,
Chapter 1c, and so on. Each window looks exactly the
same, and the data is exactly the same, but the text is
inserted into a different textbox in the userform. I've
pretty much done all of this already, so that part doesn't
matter now. What bothers me is that I am concerned with
the file size - ~1.25MB. This means there is a greater
chance of errors and whatnot.
Does anyone know how I can reduce this duplication but
still have the same data be inserted into different
textboxes (for example, Userform3.TextBox9.Text =
source.Bookmarks(1).Range, Userform3.TextBox10.Text =
source.Bookmarks(1).Range, and so on).
Thanks for any help you can give. Please e-mail me if you
need further clarification. I will try my best to explain.
TIA,
Jason
..
a client that involves a few layers of userforms and
windows. The main four userforms go with each page of
this template. Just fill in or check the textboxes and
click OK to enter the text. There is one userform that
requires they access outside bookmarked documentation. At
first I tried to set it up where they access one large
manual with many bookmarks, but I realized it would be
easier to split each chapter into its own document. So
right now they click a button on the 3rd Userform and it
performs the following macro:
Sub CommandButton1_Click()
Chapters1.Show
End Sub
This shows another window with a button for each chapter,
which is to say, each document. The client currently uses
a green screen app, punches in a few numbers 1.1 (Chapter
1 and Section 1) to retrieve that text. This seemed to be
the easiest way for me to approach this while making it
easy to use. After they access the Chapters window, they
would click on 1 to access Chapter 1, and the following
code is displayed:
Private Sub CommandButton1_Click()
Chapters1.Hide (this hides the chapter window)
Chapter1a.Show (this shows a listing of buttons for each
section in the chapter 1.1., 1.2, 1.3, and so on)
End Sub
When they choose their section, this will enter text in
the Userform 3 so they can edit or add information to it
and then click OK when doing this for each textbox that
requires this.
The code for this is as follows:
Sub CommandButton1_Click()
Dim i As Integer, source As Document
Set source = Documents.Open("C:\Documents and
Settings\Logue\My Documents\Allied
Title\exceptions\chapterone.doc")
For i = 1 To source.Bookmarks.Count
Userform3.TextBox8.Text = source.Bookmarks(1).Range
- This selects the first bookmark in chapter one. and
inserts the info in Textbox8.
Next i
Documents("C:\Documents and Settings\Logue\My
Documents\Allied Title\exceptions\Chapterone.doc").Close
SaveChanges = False
Chapter1a.Hide
End Sub
Okay, I copy and pasted the code above for each section,
and there are a lot of sections. That's not a big deal
because all I had to do was increase the bookmark amount
each time. The problem is there were three other buttons
I need to access the chapters and sections from, so as you
see above I have Chapter1a, I also created a Chapter1b,
Chapter 1c, and so on. Each window looks exactly the
same, and the data is exactly the same, but the text is
inserted into a different textbox in the userform. I've
pretty much done all of this already, so that part doesn't
matter now. What bothers me is that I am concerned with
the file size - ~1.25MB. This means there is a greater
chance of errors and whatnot.
Does anyone know how I can reduce this duplication but
still have the same data be inserted into different
textboxes (for example, Userform3.TextBox9.Text =
source.Bookmarks(1).Range, Userform3.TextBox10.Text =
source.Bookmarks(1).Range, and so on).
Thanks for any help you can give. Please e-mail me if you
need further clarification. I will try my best to explain.
TIA,
Jason
..