|
分類:[.NET 全般]
OS ウインドウズ7 エクセル 2007
今 VBA でコードを作成しています。 友人がVBなのでVBに移行の可能性が有ります。 下記コードはVBAのコードですが、VBで下記の事が可能でしょうか
下記解析データで MEMBER の4-9列を0又は1に変更する事が目的です。0か1かは計算でだします。 コンピュータ会社に確認したところ、カンマの数は全て下記のまま必要との事
下記コードはデータがない場合全てカンマをなくすコードになっています。 現状のままカンマを残しMEMBER の4-9列を0又は1に変更する事ができないでしょうか
** 解析データ ** ------------------------------------------------------------------------------- START Windows 8.00 TITLE "例題2−曲線ばり(Ex-002)" CONTROL 0,0,0, 4,9.80665, 5 M-CONTROL 1 , 1 , 0 , 0 , 0 , 0 0 , 0 , 0 , 5 , 80 1 ,2.0,1.1,60,2000 1 ,2.0,1.1,2.0,0.2,60 0 , 1 , 1 , 1 ,20,15, 1 ,,150 0 , 1 , 1 , 1 ,20,15,1.0,1.0 NODE 1,0.0,0.0,0.0,, 0,0.0,0.0,,0.0, 2,0.0,1.0,0.0,, 0,0.0,0.0,,0.0, 3,0.,0.9914448609,.13052619583,, 0,0.0,0.0,,0.0, 4,0.,0.9659258244,.25881905214,, 0,0.0,0.0,,0.0, 5,0.,0.9238795283,.38268344246,, 0,0.0,0.0,,0.0, 6,0.,0.8660253965,0.5000000126,, 0,0.0,0.0,,0.0, 7,0.,0.7933533292,0.6087614435,, 0,0.0,0.0,,0.0, 8,0.,0.7071067657,0.7071067966,, 0,0.0,0.0,,0.0, 9,0.,0.6087614088,0.7933533558,, 0,0.0,0.0,,0.0, 10,0.,0.4999999748,0.8660254184,, 0,0.0,0.0,,0.0, 11,0.,0.3826834021,0.923879545,, 0,0.0,0.0,,0.0, 12,0.,0.2588190099,0.9659258357,, 0,0.0,0.0,,0.0, 13,0.,0.1305261525,0.9914448666,, 0,0.0,0.0,,0.0, 14,0.0,0.0,1.0,, 0,0.0,0.0,,0.0, BOUNDARY 1,"" 2,1,1,1,1,1,1,,,,,, MATERIAL 1,20.0E+10,7.6923E+10,,,,"" M-MATERIAL 1 ,21, 4 , 13 , 4 , 10 , 4 , 13 , 4 , 10 , 4 ,1,1,1,1,15 SECTION G1, 1,1,1,0.02,0.02,,,,,1.2,1.2,,,,,0,0,,,,,"" MEMBER 1, 2, 3,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 2, 3, 4,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 3, 4, 5,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 4, 5, 6,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 5, 6, 7,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 6, 7, 8,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 7, 8, 9,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 8, 9, 10,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 9, 10, 11,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 10, 11, 12,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 11, 12, 13,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, 12, 13, 14,0,0,0,0,0,0,G1, 0,0,,,,,,,,,,,,,,,,,, AI-LOAD 0,0,1.0,2,0.2,0.0, 0 LOAD-DEFINITION 1,0,0,0,"",0 F-NODE 14,100.0,,,,, CALCULATION-CASE 1,"解析ケース1",1,0, 1,1.0, 0,, 0,, 0,, 0,, 0,, 0,, 0,, 0,, 0, STOP
----------------------------------------------------------------- ** データ書出し ** 下記コード VBA
Option Explicit
Sub CSV_Write()
Dim FileType, Prompt As String Dim FileNamePath As Variant '************************************************************************** ' メモ ' PRN で引き込んだエクセルの表をこのエクセル→csvで変換できる。 '**************************************************************************
Dim StartRow, StartColumn, Max_Row, Max_Column As Integer Dim Rowcnt, Columncnt As Integer Dim UsedCell As Range Dim ch1 As Long
'**************************************************************************
FileType = "CSV ファイル (*.dat),*.dat"
Prompt = "保存するファイルの名前を付けてください" '保存するファイルのパスを取得します FileNamePath = SaveFileNamePath(FileType, Prompt) If FileNamePath = False Then 'キャンセルボタンが押された Exit Sub End If ch1 = FreeFile '空いているファイル番号を取得します Open FileNamePath For Output As #ch1 'FileNamePath のファイルをオープンします Set UsedCell = ActiveSheet.UsedRange '使用しているセルの取得 StartRow = 1 StartColumn = 1 Max_Row = UsedCell.Rows.Count With UsedCell For Rowcnt = StartRow To Max_Row '各行に就いて最終行取得 Max_Column = .Cells(Rowcnt, .Columns.Count + 1).End(xlToLeft).Column - .Column + 1 For Columncnt = StartColumn To Max_Column - 1 Print #ch1, CStr(.Cells(Rowcnt, Columncnt).Value) & ","; Next Columncnt Print #ch1, CStr(.Cells(Rowcnt, Columncnt).Value) Next Rowcnt End With Close #ch1 'ファイルを閉じます
Set UsedCell = Nothing End Sub
Function SaveFileNamePath(FileType, Prompt) As Variant SaveFileNamePath = Application.GetSaveAsFilename _ (ActiveSheet.Name, FileType, , Prompt) End Function
|