Userform Coding Problem that I need help with!

D

Dan the Man

I'm hoping that someone can help me figure out a coding problem that I
SCREWED UP. I had this code in my Microsoft Word VB Editor that you see
below. The code worked PERFECTLY until I stupidly tried to edit it without
first making a backup. I know, first rule of any work is to make a backup, so
I can't believe I forgot to do that.

As an FYI, the "code" contained below was interfacing with one of my Excel
Workbooks, and allowed me to chose a client name from a dropdown menu (in
Excel), and when the name was chosen, Excel would call up a "Word", and the
Userform that was created would also open. This would then allow me to input
narrative comments into the Userform.

As a result of my "editing", I can select a client name (on the Excel
Workbook), but "Word" and "The Userform" no longer opens (actually it looks
as if it is trying to open, but cannot).

If some kind and knowledge person could look at the code below and let me
know if you see anything that I am leaving out I'd greatly appreciate it.

Dan

The Code in the MS Word Sample.doc VB Editor Module

Sub UpdateComments(parm1)

On Error Resume Next

Documents.Open FileName:=parm1

If Not FileExists(parm1) Then ' Check if file/folder exists .....
MsgBox "File " & parm1 & " does not exist", vbOKCancel
Exit Sub
End If

UserForm1.Show vbModeless

End Sub
_____________________________________________________________________
Function FileExists(fname) As Boolean
' Returns TRUE if the file exists
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True _
Else FileExists = False
End Function
 
S

Shauna Kelly

Hi

To be able to help, we're going to need some more information.

1. What version of Word and Excel?

2. Where you do start running your code. From Excel or from Word?

3. You seem to have three files: an Excel file, sample.doc (that holds your
code) and parm1. What is the relationship between these files? Is there code
in the Excel file that loads Word and opens sample.doc? Can you show us that
code?

4. The code you showed here is in sample.doc. Does sample.doc also hold
UserForm1?

5. Delete (or comment out) the line that says
On Error Resume Next
Run your code again. If it stops, tell us what line it stopped on and what
the error message is.


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
A

alborg

This could be a "Hail Mary", but have you tried to set the ShowModal property
of the UserForm to false, then opening it normally?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top