2010-12-30 4 views
1

データをCSV形式にエクスポートするマクロがあり、うまく機能しています(下のコード)。問題は、私がそれに入れているデータです。私は疑問にデータを入れたとき、それはExcelでCSVセルをマクロと組み合わせる

ファーストネーム、姓、名、パスワード、説明

を出てくる中で、私はそれを変更したいので、私は

名姓を取得、名字、ユーザー名、パスワード、説明

私がしたいのは、これを達成するために既存のマクロを操作することです。私はVBSにうまく対応していないので、正しい方向の入力や押し込みは素晴らしいものになります。

ありがとうございます!

コードは、ユーザーChance2 http://www.excelforum.com/excel-programming/679620-set-up-macro-to-export-as-csv-file.htmlからのものです。公正は公正であり、著者は正しく帰属されるべきです。私はこのサウンドを独自のものにすることについて謝罪します。

Sub Make_CSV() 
Dim sFile As String 
Dim sPath As String 
Dim sLine As String 

Dim r As Integer 
Dim c As Integer 

    r = 1 'Starting row of data 

    sPath = "C:\CSVout\" 
    sFile = "MyText_" & Format(Now, "YYYYMMDD_HHMMSS") & ".CSV" 

    Close #1 
    Open sPath & sFile For Output As #1 
    Do Until IsEmpty(Range("A" & r)) 
    'You can also Do Until r = 17 (get the first 16 cells) 
     sLine = "" 
     c = 1 
     Do Until IsEmpty(Cells(1, c)) 
      'Number of Columns - You could use a FOR/NEXT loop instead 
      sLine = sLine & """" & Replace(Cells(r, c), ";", ":") & """" & "," 
      c = c + 1 
     Loop 
     Print #1, Left(sLine, Len(sLine) - 1) 'Remove the trailing comma 
     r = r + 1 
    Loop 
    Close #1 
End Sub 
+0

「あなたの」マクロがここにリストされhttp://www.excelforum.com/excel-programming/ 679620-set-up-macro-to-export-as-csv-file.htmlを参照してください。あなたの投稿の投稿を –

+2

完了してください。私は専有的に聞こえることを意味しなかったし、私がそれを書いたようにも意味しなかった。 –

答えて

2

最も簡単な変更が「名姓」連結すなわちでsLineを割り当てるには、次のようになります。

Do Until IsEmpty(Range("A" & r)) 
'You can also Do Until r = 17 (get the first 16 cells) 
    sLine = """" & Replace(Cells(r,1) & " " & Cells(r,2), ";", ":") + """," 
    c = 1 
    Do Until IsEmpty(Cells(1, c)) 
     'Number of Columns - You could use a FOR/NEXT loop instead 
     sLine = sLine & """" & Replace(Cells(r, c), ";", ":") & """" & "," 
     c = c + 1 
    Loop 
    Print #1, Left(sLine, Len(sLine) - 1) 'Remove the trailing comma 
    r = r + 1 
Loop 
+0

これは完全に機能しました! El Ronnocoありがとう!私はもっ​​と評判があれば投票したい! –

+0

@Eric No probs :) –

関連する問題