PDA

View Full Version : Solved: Open a new Word Document from Textbox value



arcanedevice
02-26-2009, 11:03 PM
Hi
Apologies if this is answered on here somewhere, but I've searched a few variations and can't find the response.
I have a UserForm on my document that contains a text box 'FileBox'. The intention is that the User will enter a file path and name in box, then click the command button to open the nominated document.
I thought I could code it by using the Documents.Open where the file name equals Filebox.value, but can't seem to get it right.
Is anyone able to assist me on where I'm going wrong?

lucas
02-26-2009, 11:57 PM
Would it help if you could just browse for the file?
Option Explicit
Sub a()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
If .Show = -1 Then
MsgBox .SelectedItems(1)
End If
End With
End Sub

arcanedevice
02-27-2009, 12:10 AM
Thanks for the reply. I did consider that users could just browse for the file but prefer that they enter the path and the VBA will find the document as it will then start another sequence of moving data across from the newly opened 'template' to this document immediately after opening.

I had the code of
Documents.Open ("[Me.FileBox.Value]")
Unload Me

But that doesn't seem to work, so any help on how I can get it to work would be great!

BTW, please don't ask why I'm creating a duplicate as I'm still trying to work it out myself - I put it down to creating more work than is necessary, but it's what the masters want!

lucas
02-27-2009, 12:25 AM
Did you try just using the value, it seems to work just fine:

Private Sub CommandButton1_Click()
Documents.Open TextBox1.Value
Unload Me
End Sub

arcanedevice
02-27-2009, 12:50 AM
You know, I could have sworn that I'd tried that and it didn't work, and now of course it does!

Thanks lucas, much appreciated! Will mark this as solved.