By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

Can't use Dialogs.Item(wdDialogFileOpen)

P: 2
I am not able to use Dialogs.Item(wdDialogFileOpen) because of the way I'm using word inside of another application. The code below works outside of the application but not in it:

Expand|Select|Wrap|Line Numbers
  1. Sub FileInsert()
  2.  
  3. ChangeFileOpenDirectory _
  4.     "F:\Some\Folder\OnThe\Network"
  5.  
  6. With Dialogs.Item(wdDialogFileOpen)
  7.     .Name = "*.doc"
  8. If .Display = -1 Then
  9.     Selection.InsertFile FileName:=.Name, Range:="", _
  10.         ConfirmConversions:=False, Link:=False, Attachment:=False
  11.  
  12. End If
  13. End With
  14.  
  15. End Sub
I'm looking to see if there is another method to do the same thing but not using the Dialogs command. The InsertFile command still works in the application but you have to choose a file to insert. I want to select the file. Any thoughts or am I SOL.....

Thanks
Jan 23 '08 #1
Share this Question
Share on Google+
2 Replies


kadghar
Expert 100+
P: 1,295
I am not able to use Dialogs.Item(wdDialogFileOpen) because of the way I'm using word inside of another application. The code below works outside of the application but not in it:

Sub FileInsert()

ChangeFileOpenDirectory _
"F:\Some\Folder\OnThe\Network"

With Dialogs.Item(wdDialogFileOpen)
.Name = "*.doc"
If .Display = -1 Then
Selection.InsertFile FileName:=.Name, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

End If
End With

End Sub

I'm looking to see if there is another method to do the same thing but not using the Dialogs command. The InsertFile command still works in the application but you have to choose a file to insert. I want to select the file. Any thoughts or am I SOL.....

Thanks
you can always "cheat" a little bit:
create an object, open an Word Application in it, and use its dialogs ;)

Expand|Select|Wrap|Line Numbers
  1. dim obj1 as object
  2. set obj1 = createobject("word.application")
  3. With obj1.Dialogs.Item(80)  'dont use word constants outside word, check what's its numeric value.
  4.     .Name = "*.doc"
  5. If .Display = -1 Then
  6.    Selection.InsertFile FileName:=.Name, Range:="", _
  7.         ConfirmConversions:=False, Link:=False, Attachment:=False
  8. End If
  9. End With
that should help the Dialogs thing... now, i dont know what's that "selection.insertfile" for, that might cause you further problems. Give it a check.

HTH
Jan 23 '08 #2

P: 2
Hi HTH,

Thank you for your help. That worked. The insert file command is so we can put the body of a document into another document, its used for transcription in this case.

I made a few changes to perfect it. Below is the code that I'm using:

Sub InsertFile()

ChangeFileOpenDirectory _
"F:\Some\Folder\On The\Network"

Dim obj1 As Object
Set obj1 = CreateObject("word.application")
obj1.ChangeFileOpenDirectory _
"F:\Some\Folder\On The\Network"
With obj1.Dialogs.Item(80) 'dont use word constants outside word, check what's its numeric value.
.Name = "*.doc"
If .Display = -1 Then
Selection.InsertFile FileName:=.Name, Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End If
End With
obj1.Quit

End Sub

I'm not sure why I had to use the ChangeFileOpenDirectory twice but with only one of them it would open to My Docs every time and then we needed to close the object once done. Again thank you for your help I really appreciate it.
Jan 23 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.