English 中文(简体)
在进口另一份工作手册之前确定档案格式
原标题:Clear the file format before importing another workbook
  • 时间:2024-02-23 00:18:04
  •  标签:
  • excel
  • vba

请求帮助使用vba从一本工作手册中删除格式。 我的法典是行之有效的:它根据工作量选择了Excel文档。 进口另一本工作手册,但希望在进口前采用多种格式,如超链接、字体格式。 由于存在进口问题,该方案不能通知我。 太多形式的我很难要求帮助。 谢谢。

Sub add()
    
     On Error Resume Next

    Application.DisplayAlerts = False

    Application.ScreenUpdating = False

    Dim FNames As Variant
    Dim Cnt As Long
    Dim MstWbk As Workbook
    Dim ws As Worksheet

    Set MstWbk = ThisWorkbook

    FNames = Application.GetOpenFilename(fileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=True, Title:="choose Files")
    If Not IsArray(FNames) Then Exit Sub
    
    ThisWorkbook.ActiveSheet.Cells.ClearHyperlinks

    For Cnt = 1 To UBound(FNames)
        Set ws = Workbooks.Open(FNames(Cnt)).Sheets(1)
        ws.Copy After:=MstWbk.Sheets(MstWbk.Sheets.Count) 
        MstWbk.Sheets(MstWbk.Sheets.Count).Name = Left(ws.Parent.Name, InStr(2, ws.Parent.Name, ".") - 1)
        ws.Parent.Close False
    Next Cnt

    MsgBox "Import complete!", vbInformation
    
    Application.ScreenUpdating = True
    
    Application.DisplayAlerts = True

End Sub

在进口另一本工作手册之前澄清档案格式。

问题回答

Pls尝试。

    For Cnt = 1 To UBound(FNames)
        Set ws = Workbooks.Open(FNames(Cnt)).Sheets(1)
        ws.ClearFormats    ** clear all formats
        ws.Copy After:=MstWbk.Sheets(MstWbk.Sheets.Count)
        MstWbk.Sheets(MstWbk.Sheets.Count).Name = Left(ws.Parent.Name, InStr(2, ws.Parent.Name, ".") - 1)
        ws.Parent.Close False
    Next Cnt

Microsoft documentation:

明确表格方法(Excel)





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签