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
This does not work
I thank you in advance
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")