抑制弹出 - 是否要替换目标单元格

时间:2016-08-04 07:14:40

标签: vbscript

我正在尝试将csv文件转换为制表符分隔的Excel文件。我的代码正在运行,但在这样做时,我得到一个弹出式的说法 “你想要替换目标单元格”。我想压制这个弹出窗口。

file = "C:\P_TEST\Size_test.csv"

Set fso = CreateObject("Scripting.FileSystemObject")

txt = fso.OpenTextFile(file).ReadAll

fso.OpenTextFile(file, 2).Write Replace(Replace(txt, "¬", vbTab), Chr(34), "")

'Set obj = CreateObject("Scripting.FileSystemObject") 'Calls the File System Object  

Const xlDelimited = 1
Const xlNormal = -4143 

Dim Excel
Set Excel = CreateObject("Excel.Application")
With Excel
    .Workbooks.Open "\\wpkb0203\pq2\PIM\inbound\PIM_TEST\SizeGuideLookup_test.csv"
    .Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited, , , , True  'semicolon-delimited

    .ActiveWorkbook.SaveAs .ActiveWorkbook.Path & "\SizeGuideLookup_test", xlNormal
    .Quit

'    fso.DeleteFile("\\wpkb0203\pq2\PIM\inbound\PIM_TEST\SizeGuideLookup_test.csv") 'Deletes the file throught the DeleteFile function 
End With

我尝试使用以下代码来抑制它,但是然后csv文件不会从分隔符转换为制表符分隔的Excel文件。

Sub()    '
Application.DisplayAlerts = False   
file = "C:\P_TEST\Size_test.csv"

Set fso = CreateObject("Scripting.FileSystemObject")

txt = fso.OpenTextFile(file).ReadAll

fso.OpenTextFile(file, 2).Write Replace(Replace(txt, "¬", vbTab), Chr(34), "")

'Set obj = CreateObject("Scripting.FileSystemObject") 'Calls the File System Object  

Const xlDelimited = 1
Const xlNormal = -4143 

Dim Excel
Set Excel = CreateObject("Excel.Application")
With Excel
    .Workbooks.Open "C:\P_TEST\Size_test.csv"
    .Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited, , , , True  'semicolon-delimited

    .ActiveWorkbook.SaveAs .ActiveWorkbook.Path & "\SizeLookup_test", xlNormal
    .Quit

End With
End Sub

这是csv输入文件。第一行是标题。我的代码再次将csv转换为制表符分隔的Excel。我只需要压制弹出窗口。

Id¬Group1¬Size Value
65743¬StrucW¬Womens General
76544¬StrucB¬Beauty 

转换为Excel后,它变为

Id  Group1  Size Value
65743   StrucW  Womens General
76544   StrucB  Beauty 

0 个答案:

没有答案