create/open folder and word doc with folder name

megatronixs

Registered User.
Local time
Today, 22:43
Joined
Aug 17, 2012
Messages
719
Hi all,
I'm using now a macro that opens or create a folder with the ID number if is is not created it will create it.
I would like to also create a word doc with the ID number in the same folder and open it up.

So far I have this code:
Code:
Private Sub Command92_Click()
Dim strEventPhotos As String
    ' Define in one place, use in three.
    strEventPhotos = "C:\Docs\" & Me.ID
    If Len(Dir(strEventPhotos, vbDirectory)) = 0 Then
        MkDir strEventPhotos
    End If
    Shell "EXPLORER.EXE " & strEventPhotos, vbNormalFocus
End Sub

Would be great if some one could help with this.

Greetings.
 
How about something like this?

Code:
    Dim App As New Word.Application
    Dim Doc As New Word.Document
    Dim Number As Integer
    Dim strEventPhotos As String
    
    Number = Me.ID
    
    ' Define in one place, use in three.
    strEventPhotos = "C:\Docs\" & Number
    If Len(Dir(strEventPhotos, vbDirectory)) = 0 Then
        MkDir strEventPhotos
    End If
    
   
   
    Set App = CreateObject("Word.Application")
    App.Visible = True
    Set Doc = App.Documents.Add
    
      
    Doc.SaveAs2 (strEventPhotos & "\" & Number)
 
Hi,
Thanks for the help.
For some strange reasons I get compile error: user defined type not defined. No clue what that is.

Thanks and greetings.
 
In the VBA editor, under references, make sure the Microsoft Office and Microsoft Word library are checked. That should hopefully do the trick.
 

Users who are viewing this thread

Back
Top Bottom