#1
|
|||
|
|||
Is it possible to use a .txt file to populate a msgbox prompt field
I get a call stack error when I try to use the following code to populate a msgbox prompt field:
Quote:
Quote:
"ERROR Message from Module " & chr(34) & strModuleName & chr(34) & _ "a Macro named, " & chr(34) & strMacroName & Chr(34) & _ "[etcetera]" I frequently modify my error messages and other messages, and it would be much easier for me to produce my standardized text using a python script; and I would save a lot of time if I could import those error message files into a msgbox prompt field. I would appreciate any suggestions, that might [1] enable me to import text to Msgbox prompt field from files, and/or [2] help me learn more about call stacks, and how to handle call stack issues. Thanks, Marc |
#2
|
||||
|
||||
Maybe the following is more what you had in mind.
Code:
Dim TextFile As Integer Dim FilePath As String Dim FileContent As String Dim FileNum As Integer Dim DataLine As String 'File Path of Text File FilePath = "E:\Zmani\Logging\202004011500__Tmp_61385499383529 09.py_.txt" FileNum = FreeFile() Open FilePath For Input As #FileNum While Not EOF(FileNum) Line Input #FileNum, DataLine FileContent = FileContent & DataLine & vbCr Wend FileContent = Left(FileContent, Len(FileContent) - 1) Close 'Report Out Text File Contents MsgBox FileContent
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
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'sBut 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 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 |
#4
|
||||
|
||||
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Quote:
Marc |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How To Make 2013 Populate To Field | abraxis | Outlook | 2 | 08-10-2018 06:41 AM |
populate list with unique field value on repeated field value | sukusnairss | Excel | 1 | 04-03-2018 11:47 PM |
Have Text Entered in Content Control / PreDefined Field Populate Field in Footer | bzowk | Word | 1 | 04-14-2016 11:50 AM |
Prompt a macro to run when opening a specific file type | gmanword | Word VBA | 5 | 11-30-2013 02:55 PM |
Openin File in Use Locks PC Up, No Read only Prompt | barkster | Office | 0 | 06-08-2010 01:22 PM |