View Single Post
 
Old 04-26-2020, 01:24 PM
marceepoo marceepoo is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Sep 2012
Posts: 22
marceepoo is on a distinguished road
Default

Dear Graham:

While doing some research to understand how and why your solution worked, I came across the following:

The "FreeFile function" page (located at: FreeFile function (Visual Basic for Applications) | Microsoft Docs), which led me to:
1. The "Open statement" page (located at: 404 - Content Not Found | Microsoft Docs and
2. The "Writing data to files" page (located at: Writing data to files (VBA) | Microsoft Docs)
which contained two information items that perplex me:

The first item was an admonition not to use the Open statement in Word Vba:
Note[:] The Open statement should not be used to open an application's
own file types. For example, don't use Open to open a Word document,
a Microsoft Excel spreadsheet, or a Microsoft Access database.
Doing so will cause loss of file integrity and file corruption.
But my subsequent use of Word's macro recorder (View, Record macro ...), seemed to recommend that I may or should use the Open statement:
Code:
Sub subOpenExistingWordDoc()
        '
            ChangeFileOpenDirectory _
                "E:\DirName"
            Documents.Open FileName:="Filename.docx", ConfirmConversions:=False, _
                 ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
                PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
                WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:="", _
                DocumentDirection:=wdLeftToRight
        End Sub
I think that I am missing some idea that has a role in why you used the FreeFile function in your solution.
I recognize that you were using the Open statement for reading as distinguished from writing.
But I also suspect that I am missing something central.
I would appreciate it if you could point me to where I could get some insight into what the admonition not to use the Open statement is all about.


The second item that perplexed me on "Writing data to files" page was the table stating that I could write to a file using either the "Print #" or "Write #" statements.

I could not find pages where Microsoft explains how each of those statements operate, e.g., the syntax and any related information, particularly for the "Print #" statement, which I have never seen used in VBA for the purpose of recording information to a file.
Do you know where I could find more info about the "Print #" and "Write #" statements, to which that page was referring?

If I shouldn't be asking you this type of question, or if you don't have time to waste on these things, please forgive me for asking.

Thanks again the help you gave me.

Marc
Reply With Quote