VBA - PasteSpecial Error и переход к следующей строке в Excel

Я использовал этот файл FileSaver.js . В моем случае с файлами csv я сделал это (в coffescript):

  $.ajax
    url: "url-to-server"
    data: "data-to-send"
    success: (csvData)->
      blob = new Blob([csvData], { type: 'text/csv' })
      saveAs(blob, "filename.csv")

Я думаю, что для наиболее сложного случая данные должны обрабатываться должным образом. Под капотом FileSaver.js реализует тот же подход ответа Джонатан Аменд .

-1
задан Yolo_chicken 5 March 2019 в 20:42
поделиться

1 ответ

Исправлен синтаксис при копировании из Word, можно попробовать

Sub Loop_WordToExcel()

    Dim WdApp As Word.Application
    Dim WdDoc  As Document
    Dim docName As String
    Dim strFile As String
    Dim directory As String
    Dim Rng As Range
    Dim Offst As Long, Txt As String

    directory = "C:\users\user\Desktop\Folder1\" ' Change to your path
    strFile = Dir(directory & "*.docx")          ' docx  extension added to prevent attempt to open other type of files

    Set Rng = Application.InputBox(Prompt:="Enter row", Type:=8) '


    Set WdApp = CreateObject("Word.Application")
    WdApp.Visible = True


    Do While strFile <> ""
    Set WdDoc = WdApp.Documents.Open(Filename:=directory & strFile)
    Rng.Offset(Offst, 0).Value = WdDoc.Name
    'First Name

    WdDoc.Tables(1).Cell(1, 3).Range.Copy           'will raise error if table& corres cell not exists , My use error handrel
    Rng.Offset(Offst, 1).Activate
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False    'Assumed want get name in Column B

    'is is suggested to use the below two lines instead of paste special above three lines
    'Txt = WdDoc.Tables(1).Cell(1, 3).Range.Text      'will raise error if table& corres cell not exists , My use error handrel
    'Rng.Offset(Offst, 1).Value = Txt

    WdDoc.Close SaveChanges:=False
    Offst = Offst + 1
    strFile = Dir
    Loop

WdApp.Quit
End Sub

Всегда желательно добавлять ссылку на библиотеку объектов Microsoft Word.

0
ответ дан Ahmed AU 5 March 2019 в 20:42
поделиться
Другие вопросы по тегам:

Похожие вопросы: