I'm trying to know how to save a content of a TextField to a File, like a .txt, using a Common Dialog, only a command dialog in Visual Basic 6, i need this using a only a common dialog, because i'm trying to do the same aplication in eVB, and eVB does not support this methods:
Dim objFSO As New Scripting.FileSystemObject
Dim objStream As Scripting.TextStream
Please help me, i'm needing this so much! Thanks.
Dim fileHandle As File
Set fileHandle = CreateObject("FILECTL.File")
fileHandle.Open "filename.txt", 2
fileHandle.LinePrint "some text"
fileHandle.Close
Set fileHandle = Nothing
I am not familiar with eVB, but does it support legacy style file operations like this:
Open "filename.txt" for output as #1
Print #1, yourtextfield.text
Close #1
Related
We use PcSchematic for our electric drawings. And we use PDM to manage the revision. I would like to write into the pcschematic file with the current revision from PDM.
A pcSchematic file can be opened with a notepad. so what I would like to do is:
Dim filePath as string = "C:\16368.04.PRO"
Open file with notepad Process.Start("notepad", filePath)
find and replace a line
save
close
I have tried this:
Dim objFSO
Dim objTS
objFSO = CreateObject("Scripting.FileSystemObject")
objTS = objFSO.OpenTextFile(filePath, 2)
From this Text file in VBA: Open/Find Replace/SaveAs/Close File
but it only seems to work for .txt files
Can anyone point me in the right direction?
I am thinking to make a excel file which can generate a headre file for my c++ source file.
Previoulsy we used to generate .h files using excel but i dont know the logic behind that(Hope some macros using for that).
My header file contains this many data and my intention is to give "MYapp Alpha 0.0.3" through excel file because the version number changes for each release. If I used excel file then I can edit that excel and it creates .h file for me, later some more informations I can make configurable through excel file.
Is it possible to write macro that edit "MYapp Alpha 0.0.3" without touching other
#define APP_FLASH_APP_ID 0x123
#define APP_VERSION_NUM "MYapp Alpha 0.0.3 "
#define APP_PRODUCT_NAME "TPI "
#define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM
#define APP_RELEASE_DATE_STR "10/11/13"
#define APP_SOFTWARE_PARTNUM_LEN 10
Some valuable help or suggestions needed
Have a great day
I think this could help you:
Sub test()
Const strVerNumber As String = "0.0.4"
Dim FS, TSsource
Set FS = CreateObject("Scripting.FileSystemObject")
Set TSsource = FS.OpenTextFile("C:\test.txt", 1, 2)
Dim tmpString As String
tmpString = TSsource.ReadAll
TSsource.Close
tmpString = Replace(tmpString, _
"MYapp Alpha 0.0.3", _
"MYapp Alpha " & strVerNumber)
Dim TSout
Set TSout = FS.Createtextfile("C:\testOUT.txt", True)
TSout.Write tmpString
TSout.Close
End Sub
See these methods: OpenTextFile, CreateTextFile, ReadAll and Write
Are you talking about something like this:
Formulas:
Results:
Well basically a .h file is a text file. So you need to do some string processing, open a text file, print the data in it and close it.
To open and close a text file use this:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile("D:\test.h")
oFile.WriteLine "tfadfadsest"
oFile.Close
Set fso = Nothing
Set oFile = Nothing
I retrieved a HTML file that I want to save using a textstream object from FileSystemObjects and it produces an empty file.
When I use MsgBox to display the stream right before the write command it shows all the HTML code I want, but it doesn't write the code to the file. Any suggestions?
Dim FSO As FileSystemObject
Dim FSOFile As TextStream
Dim FilePath As String
FilePath = "C:\myhtml.html"
Set FSO = New FileSystemObject
Set FSOFile = FSO.OpenTextFile(FilePath, 2, True)
FSOFile.Write myContent ' String object holding the HTML textstring
FSOFile.Close
I basically am trying to export my gmail inbox folder which I want to use as an event listener (so I can tell another machine what it is supposed to do.) .
On your comments so far:
- riteLine does not make any difference
- OpenTextFile creates non-existing files and it also creates the file and writes any other string that I manually type in, s.a. FSOFile.WriteLine "Nothing works"
- For completeness: CreateTextFile also did not help.
Any likely problem of writing the HTML code using the FSO stream?
Try WriteLine instead of just Write.
See Example: http://msdn.microsoft.com/en-us/library/aa242706%28v=vs.60%29.aspx
I'm writing a macro which goes through a document and tries to parse it by Style. Right now, anything in the designated style is copied onto the immediate window. Is there a way to automate the macro further to move the text from the immediate window into a txt file? Otherwise, anyone using the macro would not be able to see the text unless they opened up VBA, correct?
Here's my suggestion: write to the immediate window AND to a file at the same time. Examples below.
Why make the information first transit in the immediate window, and only then write it to a file from there? That just sounds perversely and uselessly difficult!
Dim s As String
Dim n As Integer
n = FreeFile()
Open "C:\test.txt" For Output As #n
s = "Hello, world!"
Debug.Print s ' write to immediate
Print #n, s ' write to file
s = "Long time no see."
Debug.Print s
Write #n, s ' other way of writing to file
Close #n
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
Dim txs As Scripting.TextStream
Set txs = FSO.CreateTextFile("C:\test2.txt")
s = "I like chickpeas."
Debug.Print s ' still writing to immediate
txs.WriteLine s ' third way of writing to file
txs.Close
Set txs = Nothing
Set FSO = Nothing
Note that this last bit of code requires a reference to be set: Tools > References > checkmark at Microsoft Scripting Runtime.
Put this code to immediate window and hit enter to write the List to JSON text in C#.
System.IO.File.WriteAllText(#"C:\Users\m1028200\Desktop\Json2.txt",
JsonConvert.SerializeObject(resultsAll));
I would recommend to use some best-practices-based logging framework like VBA Logging, which supports file logging or console configurably in parallel etc.
example usage (e.g. in some Foo.bas module):
Sub MySub()
Logging.setModulName (Application.VBE.ActiveVBProject.Name)
Set log = Logging.getNewLogger(Application.VBE.ActiveVBProject.Name)
Call log.setLoggigParams(Logging.lgALL, True, True, True) ' log ALL to Console, Buffer, File
log.logINFO "This is my message ..", "MySub"
End Sub
resulting in something like (both in console and vba_logging.log file):
(16.12.2018 13:08:30)[XlsxMgr::MySub]-INFO: This is my message ..
where the log config file looks like this:
## vba_logging.properties
LOG_LEVEL = info
LOG_TO_CONSOLE = True
LOG_TO_BUFFER = True
I get the following error message when I try the following:
Dim XL As New Microsoft.Office.Interop.Excel.Application
XL.Visible = True
XL.Workbooks.Open(XLTemplatePath)
XL.SaveWorkspace(XLSaveReportPath)
XL.Workbooks.Close()
XL.Workbooks.Open(XLSaveReportPath)
"Excel cannot open the file 'ContactReports.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
What I would like to do is Open a excel file that is the XLTemplatePath and the either rename or save the file at the XLSaveReportPath and then use that renamed/saved file to fill the report out.
I am using Visual Studio 2008 in VB.NET
The saveworkspace method does not save the file. It save the workspace in the format xlw even though you are naming the file you are saving the workspace in as xls. When you try and open the document you are opening a worspace and you recieve the error.
To have this work correctly you need to get the workbook so you can sabe the workbook instead of the application.
Dim XL As New Microsoft.Office.Interop.Excel.Application
Dim XLWorkbook as new Microsoft.Office.Interop.Excel.Workbook
XL.Visible = True
XLWorkbook = XL.Workbooks.Open(XLTemplatePath)
XLWorkbook.SaveAs(XLSaveReportPath)
XL.Workbooks.Close()
XL.Workbooks.Open(XLSaveReportPath)
Should do the trick. Let us know if you have any problems.
Heare are the MSDN refrences for your review:
Application.SaveWorkspace Method
Workbook.SaveAs Method
I have used the following Visual Basic code to work with Microsoft Excel 2003. The key difference (other than Visual Basic 6 vs VB.Net) is that I use the SaveAs method of the Workbook object rather than the SaveWorkspace method.
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
Set ExcelDoc = ExcelApp.Workbooks.Open(FileName:=XLTemplatePath, ReadOnly:=True)
ExcelDoc.SaveAs(FileName:=XLSaveReportPath)
ExcelDoc.Close(SaveChanges:=False)
ExcelApp.Workbooks.Open(FileName:=XLSaveReportPath)