Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-30-2017, 02:20 AM
gerison gerison is offline open saved word document in external editor. Windows 10 open saved word document in external editor. Office 2010 64bit
Novice
open saved word document in external editor.
 
Join Date: Nov 2017
Posts: 8
gerison is on a distinguished road
Default open saved word document in external editor.


Hello! Recently this forum helped me to solve the problem to save a document, close it and open it in another editor. Part of the code was like this: strName = Replace(ActiveDocument.FullName, ".docx", ".txt") ActiveDocument.SaveAs2 FileName:=strName, FileFormat:=wdFormatText ActiveDocument.Close 0 RetVal = Shell("notepad.exe " & strName, 1) It works until there are blank spaces in the file name. Example: This is the regular namestructure of my files. "Ka,17-11-27,Brief lang an Lackner Josef.docx" This File was saved, but got an error message that the external editor cant't find the file. Wheras a file like: Ka,17-11-27,xxxxxxxxxxxxxxxxxxxxxxxx.docx is saved and opend in the editor. I was looking for restictions as to file names but couldn't found any. I'm wondering if blank sapces in filenames are forbidden somehow. Can one of you provide me with any help or an hint where I can find a solution. Thanks in advance. gerald
Reply With Quote
  #2  
Old 11-30-2017, 06:25 AM
gmayor's Avatar
gmayor gmayor is offline open saved word document in external editor. Windows 10 open saved word document in external editor. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Spaces are not barred in filenames and the code you posted (essentially as below) works without any problem with your filename example

Code:
Sub Macro1()
Dim retval As Object
Dim strName As String
    On Error Resume Next
    strName = Replace(ActiveDocument.FullName, ".docx", ".txt")
    ActiveDocument.SaveAs2 FileName:=strName, FileFormat:=wdFormatText
    ActiveDocument.Close 0
    retval = Shell("notepad.exe " & strName, 1)
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-30-2017, 06:32 AM
gerison gerison is offline open saved word document in external editor. Windows 10 open saved word document in external editor. Office 2010 64bit
Novice
open saved word document in external editor.
 
Join Date: Nov 2017
Posts: 8
gerison is on a distinguished road
Default

Thank you again for your fast response. Using the scribt on filename "Ka,17-11-27,Brief lang an Lackner Josef.docx" saves the .txt file and generates en error message on opening the editor: file not found. Using the the scribt on filename "Ka,17-11-27,xxxxxxxxxxxxxxxxxxxxxxxx.docx" saves the .txt file and opens it in the editor for further editing. This is what I don't understand. It doesn't relate to the lenght of the file name as well. As soon as there are spaces the error occours. This is why I was thinking about restrictions of the filname itself on running the scribt. The scribt itself works great, and I thank you again. Maybe ther is a trick to it.
Reply With Quote
  #4  
Old 02-01-2018, 08:45 AM
gerison gerison is offline open saved word document in external editor. Windows 10 open saved word document in external editor. Office 2016
Novice
open saved word document in external editor.
 
Join Date: Nov 2017
Posts: 8
gerison is on a distinguished road
Default

Hello again! You've been right, for notepad.

But I'm coming back to that issue, beacause I can't ajust it to my needs and make it work. I used the save to txt and open in notepad as a example to keep it simple and understand the process.

In the end I ajusted the scribt to my needs, which are: convert to .tex and open it in a Tex Editor.

Code:
Sub saveastxt()
Dim RetVal As Object
Dim strDelete As String
Dim strName As String
    On Error Resume Next
    ActiveDocument.Save
    If ActiveDocument.Path = "" Then
        MsgBox "Document not saved!"
        GoTo lbl_Exit
    End If
    strDelete = ActiveDocument.FullName
    strName = Replace(ActiveDocument.FullName, ".docx", ".tex")
    ActiveDocument.SaveAs2 FileName:=strName, FileFormat:=wdFormatText
    ActiveDocument.Close 0
    RetVal = Shell("C:\Program Files (x86)\Texmaker\texmaker.exe " & strName, 1) 'Don't open the saved .txt file
    Kill strDelete
lbl_Exit:
    Exit Sub
End Sub
It works, but only without any spaces in the filname. Otherwise the editor opens, showing no file, or in case of another editor: it opens with the massage, file not found. I tried several tex editors, all mention the same problem.

I just can't get it solved by myself. I simply don't understand why it works with notepad and not with the other editors.

I really would appreciate any help, and I'm willed to donate for a solution
Reply With Quote
  #5  
Old 02-01-2018, 02:01 PM
gerison gerison is offline open saved word document in external editor. Windows 10 open saved word document in external editor. Office 2016
Novice
open saved word document in external editor.
 
Join Date: Nov 2017
Posts: 8
gerison is on a distinguished road
Default Solved

Hello again! The Problem could be solved with the ollowing line. RetVal = Shell("C:\Program Files (x86)\Texmaker\texmaker.exe """ & strName & """", 1) gerald
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
open saved word document in external editor. Creating a macro from a non-saved Word doc that duplicates the current open document and saves it mike0215 Word VBA 3 11-17-2017 01:40 PM
open saved word document in external editor. Cannot open saved Word document otherlunds Word 1 09-01-2014 05:41 AM
open saved word document in external editor. Formula to open external file with specific program (like open with) pemartins Excel 16 02-24-2014 11:39 PM
open saved word document in external editor. Run-time error '1004': Document not saved. The document may be open... doctor_who12 Excel Programming 1 01-22-2014 04:47 PM
Preventing word/excel from trying to open external template locations Perhill Office 0 03-02-2011 04:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft