Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open excel file and overwrite and check

Status
Not open for further replies.

suleymanyaman

Industrial
Jul 30, 2013
29
SE
Hi dear friend or members

I have some values and I want to overwrite excel file before I create path in down.
However I didnot open created file.Also I want to check this file was opened do something.

Thank you for helping.

If strsearch = sname Then
sTemp = sname + " = " + CStr(a(9)) + ", " + CStr(a(10)) + ", " + CStr(a(11))

'Msgbox sTemp

oLocation = "C:\Macro Files\" & partName1 & "." & exportFormat 'before is created

'I want to open again this excel file
'if this file is "open or activated"
' oExcel.Cells(1,1)="NAME" ...


End If
 
Replies continue below

Recommended for you

I try to open and overwrite and also check if it is opened.I mean these 3 step like in below but I am not succesfull.(maybe this is more clear now)


If strsearch = sname Then
sTemp = sname + " = " + CStr(a(9)) + ", " + CStr(a(10)) + ", " + CStr(a(11))

Dim Mydirectory As String
Dim MyExtension As String
Dim MyFileName As String
Dim FileCheck As String
Mydirectory = "C:\Macro Files\" 'before is created
MyExtension = ".xls"
MyFileName = Mydirectory + partName1 + MyExtension
On Error Resume Next

FileCheck = Dir$(MyFileName)
If FileCheck = partName1 + MyExtension Then

Set oExcelworkbook = oExcel.Workbooks.Open(MyFileName)
Set oExcelSheet = oExcelworkbook.Worksheets(1)
If oExcel.workbook.worksheets.Open = True Then
oExcel.cells(5, 5) = "PartName"
oExcel.cells(6, 5)=sname
End If
End If
End If
 
First of all in below I created xls files(thanks E.Ross) and save defined path. And also I want to access this file then I want to check "if xls opened or activated" else if not I want to open and I want to overwrite these values "oExcel.cells(6, 5)=sname" sname(1),sname(2)....

I want to check If open because each sname value returns end of the sub/end sub which means I didnot store sname values and also I did not store snameS' coordinate values and I did not do any calculation.I am thinking that If I save these values on excel file every loop then I can calculate on excel.

For example,
X Y Z
sname- abc.1 10 20 30
dfg.1 50 60 70
sname is sub-partname.

End of the first sub/end sub

I reached abc.1 10 20 30 values before disapear or lost these values I want to save on excel file
Then method reachs dfg.1 50 60 70 values again I check excel is opened else (if not) excel should be activated finally saved dfg.1 values

Sub createSaveFile()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
'Input box to select txt or xls

exportFormat = InputBox("Please choose format to export the tree as._ Type 'xls' ") 'thats why maybe later it can be changed xls to txt flexible

If exportFormat <> "xls" Then

MsgBox "Did not enter txt or xls. Program cancelled, please retry macro."
Else
'Input box to enter name of file

partName1 = InputBox("Please enter the file name.")
'Input box to enter file location

oLocation = "C:\Macro Files\" & partName1 & "." & exportFormat
productDocument1.ExportData oLocation & partName1 & "." & exportFormat, "txt"

End If

End Sub

Ps. My english can be weak and also I am student so new in catia also script or macro.If I didnt explain clearly,I can try again.
Thank you ferdo.
 
Yes,exactly you are right.in meanwhile I got CAT Portable Script but I didnot examine deeply. I will look this folder again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top