• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro create file next to the file word excel

Visor

Member
I would like to help me solve the following, I want a button to create a word file, but that is located in the same place where is the excel file, but if it already exists then open it and if it is already open then show the message and It's open.

I have this code but it works ne me to create the file. I have selected the reference .. In Microsoft Word 15 references. I excel 2013 64

Code:
Private Sub CommandButton2_Click()
Dim Archivo As String
Dim objWord As Word.Application
    Archivo = ThisWorkbook.Path & "\PlanClase.docx"
    CreateObject("Word.Application").Documents.Add
    CreateObject("Word.Application").SaveAs "Archivo"
  With CreateObject("word.application")
    If Dir(Archivo) = "" Then
    'If the file does not exist in the path where the excel file,
'Then the file is created with the specified name
    CreateObject("Word.Application").Documents.Add
    CreateObject("Word.Application").SaveAs "Archivo"
        MsgBox ("file created!")
      Else
‘If the file already exists then open it, but check whether this already open
    'If Archivo Is Nothing Then
    'ruta = Word.Application.Path
    'Word.Application.Open Filename:=Archivo
    'Else
    '    MsgBox " The file was already open "
  '  End If
  'Exit Sub
    'Else
    .Documents.Open Archivo
        End If
      .Visible = True
      .Activate
      End With
End Sub

This does not work
Code:
CreateObject("Word.Application").Documents.Add
CreateObject("Word.Application").SaveAs "Archivo"
MsgBox ("Archivo creado")
I thank you in advance
 
Back
Top