Macro which save data a text file...
Macro which save data a text file...
(OP)
hello.
I find macro which allow save data in excell file.But i want save data in text file.How make that?Do You have any ideas?I willbe graetfull for yours help...
I find macro which allow save data in excell file.But i want save data in text file.How make that?Do You have any ideas?I willbe graetfull for yours help...






RE: Macro which save data a text file...
RE: Macro which save data a text file...
CODE
Dim fso As Scripting.FileSystemObject
Dim sFilePath As String
Dim myOutFile As Scripting.TextStream
Dim i As Long
Set fso = CreateObject("Scripting.FileSystemObject")
sFilePath = "C:\TEMP\OutFile.txt"
Set myOutFile = fso.OpenTextFile(sFilePath, ForWriting, Create:=True)
myOutFile.WriteLine "Here is the first line"
myOutFile.WriteLine "Here is the second line"
For i = 3 To 9
myOutFile.WriteLine "Here is line number " & i
Next i
myOutFile.Write "All of this text is on one line"
myOutFile.Write " because we used ""Write"" instead of ""WriteLine"""
myOutFile.WriteBlankLines 4
myOutFile.WriteLine "This last line comes after 4 blank lines."
myOutFile.Close
Set myOutFile = Nothing
Set fso = Nothing
End Sub
RE: Macro which save data a text file...
is it!
RE: Macro which save data a text file...
Dim fso As Scripting.FileSystemObject
In my version SolidWorks i don't have something like: Scripting, so I cannot difine fso like that...
I use SolidWorks2005 and maybe tahts is& the problem..; What You think?
RE: Macro which save data a text file...
RE: Macro which save data a text file...
RE: Macro which save data a text file...
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swSurf As SldWorks.Surface
Dim Feature As SldWorks.Feature
Dim MathPoint As SldWorks.MathPoint
Dim RefPoint As SldWorks.RefPoint
Dim vRefPointFeatureArray As Variant
Dim XYZ As Variant
Dim fso As Scripting.FileSystemObject
Dim sFilePath As String
Dim myOutFile As Scripting.TextStream
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFace = swSelMgr.GetSelectedObject5(1)
Set fso = CreateObject("Scripting.FileSystemObject")
sFilePath = "C:\TEMP\OutFile.txt"
Set swSurf = swFace.GetSurface
vRefPointFeatureArray = swModel.FeatureManager.InsertReferencePoint(4, 0, 0.01, 1)
Set Feature = vRefPointFeatureArray(0)
Set RefPoint = Feature.GetSpecificFeature2
Set MathPoint = RefPoint.GetRefPoint
XYZ = MathPoint.ArrayData
Set MathPoint = Nothing
Set RefPoint = Nothing
Set Feature = Nothing
swApp.SendMsgToUser " Center of selected surface: " _
& vbCrLf _
& vbCrLf & " X = " & XYZ(0) * 1000 & " mm" _
& vbCrLf & " Y = " & XYZ(1) * 1000 & " mm" _
& vbCrLf & " Z = " & XYZ(2) * 1000 & " mm"
Set myOutFile = fso.OpenTextFile(sFilePath, ForWriting, Create:=True)
myOutFile.WriteLine "Here is the first line"
myOutFile.Close
Set myOutFile = Nothing
Set fso = Nothing
End Sub
RE: Macro which save data a text file...
CODE
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swSurf As SldWorks.Surface
Dim Feature As SldWorks.Feature
Dim MathPoint As SldWorks.MathPoint
Dim RefPoint As SldWorks.RefPoint
Dim vRefPointFeatureArray As Variant
Dim XYZ As Variant
Dim fso As Scripting.FileSystemObject
Dim sFilePath As String
Dim myOutFile As Scripting.TextStream
Dim Msg As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFace = swSelMgr.GetSelectedObject5(1)
Set fso = CreateObject("Scripting.FileSystemObject")
sFilePath = "C:\TEMP\OutFile.txt"
Set swSurf = swFace.GetSurface
vRefPointFeatureArray = swModel.FeatureManager.InsertReferencePoint(4, 0, 0.01, 1)
Set Feature = vRefPointFeatureArray(0)
Set RefPoint = Feature.GetSpecificFeature2
Set MathPoint = RefPoint.GetRefPoint
XYZ = MathPoint.ArrayData
Set MathPoint = Nothing
Set RefPoint = Nothing
Set Feature = Nothing
Msg = " Center of selected surface: " _
& vbCrLf _
& vbCrLf & " X = " & XYZ(0) * 1000 & " mm" _
& vbCrLf & " Y = " & XYZ(1) * 1000 & " mm" _
& vbCrLf & " Z = " & XYZ(2) * 1000 & " mm"
swApp.SendMsgToUser Msg
Set myOutFile = fso.OpenTextFile(sFilePath, ForWriting, Create:=True)
myOutFile.WriteLine Msg
myOutFile.Close
Set myOutFile = Nothing
Set fso = Nothing
End Sub
RE: Macro which save data a text file...
RE: Macro which save data a text file...
You could have found this answer quicker by searching the internet for either "OpenTextFile" or "TextStream".
RE: Macro which save data a text file...