TA的每日心情 | 开心 2024-7-19 12:08 |
---|
签到天数: 268 天 [LV.8]以坛为家I
|
发表于 2015-1-31 18:35:15
|
显示全部楼层
本帖最后由 cnelecn 于 2015-1-31 21:02 编辑
周末抽空弄了各welltop的vba,给工作带了方便,分享一下。欢迎批评指正。
代码:
Sub 按钮1_Click()
Dim str As String
Dim iRow, iColumn As Integer
Dim Source
Source = ActiveSheet.UsedRange
Open ThisWorkbook.Path & "\Welltops FromExcel.txt" For Output As #1
'【header】
str = str & "# Petrel well tops by Guochen" & Chr(13) & Chr(10)
str = str & "# Unit in X and Y direction: m" & Chr(13) & Chr(10)
str = str & "# Unit in depth: m" & Chr(13) & Chr(10)
str = str & "Version 2" & Chr(13) & Chr(10)
str = str & "BEGIN Header" & Chr(13) & Chr(10)
str = str & "MD" & Chr(13) & Chr(10)
str = str & "Type" & Chr(13) & Chr(10)
str = str & "Surface" & Chr(13) & Chr(10)
str = str & "Well" & Chr(13) & Chr(10)
str = str & "END HEADER" & Chr(13) & Chr(10)
'【content】
For iRow = 2 To UBound(Source)
For iColumn = 2 To UBound(Source, 2)
str = str & CheckValue(ActiveSheet.Cells(iRow, iColumn)) & vbTab
str = str & Horizon & vbTab & ActiveSheet.Cells(1, iColumn) & vbTab & ActiveSheet.Cells(iRow, 1) & vbTab
str = str & Chr(13) & Chr(10)
Next
Next
Print #1, str
Close #1
End Sub
Function CheckValue(strValue As String) As String
' 空值替换
If Len(strValue) < 1 Then
CheckValue = "-999"
Else
CheckValue = strValue
End If
End Function
|
-
welltop
评分
-
查看全部评分
|