九色国产,午夜在线视频,新黄色网址,九九色综合,天天做夜夜做久久做狠狠,天天躁夜夜躁狠狠躁2021a,久久不卡一区二区三区

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
python – 腳本更改到多個Excel工作簿

我試圖對一些excel工作簿(超過20個)進行大量更改.每個工作簿包含大約16個單獨的工作表,我想編寫一個腳本,它將循環(huán)遍歷每個工作簿,工作表包含內(nèi)部并寫入/修改我需要的單元格.我需要保留所有字符串驗證,宏和格式.所有工作簿都是2007年的格式.

我已經(jīng)看過python excel庫和PHPexcel,但是宏,按鈕,公式,字符串驗證和格式化,并且在編寫新工作簿時不會保留.有沒有一種簡單的方法可以做到這一點,或者我是否必須單獨打開每個工作簿并提交更改.我試圖避免在VBscript中創(chuàng)建一個宏,并且必須單獨打開每個工作簿以提交我需要的更改.

解決方法:

我避免使用像瘟疫這樣的多個工作簿這是一個痛苦,如果這是一個持續(xù)的要求,那么我建議回顧你的工作簿設(shè)計,看看你是否可以合并回一個工作簿.我經(jīng)??吹矫總€工作簿都按月保存,當(dāng)時他們應(yīng)該有一個工作簿,其中一個工作表包含原始數(shù)據(jù),每行代表一個月,然后是另一個顯示用于查找用戶選擇的原始數(shù)據(jù)的工作表.這是一個非常大的概括,你很可能處于完全不同的情況.

如果它一次性 – 我知道它不是你想要的,但我認(rèn)為你最好使用VBA循環(huán)工作簿.像(未經(jīng)測試)的東西:

Excel 2003:

Sub AdjustMultipleFiles()Dim lCount As LongDim wbLoopBook As WorkbookDim wsLoopSheet As WorksheetWith Application    .ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = FalseEnd WithWith Application.FileSearch        .NewSearch        '// Change path to suit        .LookIn = "C:\MyDocuments"        '// ALL Excel files        .FileType = msoFileTypeExcelWorkbooks        '// Uncomment if file naming convention needed        '.Filename = "Book*.xls"            '// Check for workbooks            If .Execute > 0 Then                '// Loop through all.                For lCount = 1 To .FoundFiles.Count                    '// Open Workbook x and Set a Workbook variable to it                    Set wbLoopBook = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)                        '// Loop through all worksheets                        For Each wsLoopSheet In wbLoopBook.Worksheets                            '//Update your worksheets here...                        Next wsLoopSheet                    '// Close Workbook & Save                    wbLoopBook.Close SaveChanges:=True                    '// Release object variable                    Set wbLoopBook = Nothing            Next lCount        End IfEnd WithWith Application    .ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = TrueEnd WithEnd Sub

對于EXCEL 2007:

Sub AdjustMultipleFiles()    Dim sFileName As String    Dim wbLoopBook As Workbook    Dim wsLoopSheet As Worksheet    With Application        .ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False    End With    '// Change path to suit    ChDir "C:\Documents"    '// ALL Excel 2007 files    sFileName = Dir("*.xlsx")    Do While sFileName <> ""        '// Open Workbook x and Set a Workbook variable to it        Set wbLoopBook = Workbooks.Open(Filename:=sFileName, UpdateLinks:=0)        '// Loop through all worksheets        For Each wsLoopSheet In wbLoopBook.Worksheets        '//Update your worksheets here...        Next wsLoopSheet        '// Close Workbook & Save        wbLoopBook.Close SaveChanges:=True        '// Release object variable        Set wbLoopBook = Nothing        '//Next File        sFileName = Dir        '//End Loop    Loop    With Application        .ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True    End WithEnd Sub

Excel 2007(FileSystemObject – LateBinding)

Sub AdjustMultipleFiles()    Dim wbLoopBook As Workbook    Dim wsLoopSheet As Worksheet    With Application       .ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False    End With    With CreateObject("Scripting.FileSystemObject")        '// Change path to suit        For Each File In .GetFolder("C:\Documents").Files            '// ALL Excel 2007 files            If .GetExtensionName(File) = "xlsx" Then                '// Open Workbook x and Set a Workbook variable to it                Set wbLoopBook = Workbooks.Open(Filename:=File.Path, UpdateLinks:=0)                '// Loop through all worksheets                For Each wsLoopSheet In wbLoopBook.Worksheets                    '//Update your worksheets here...                Next wsLoopSheet                '// Close Workbook & Save                wbLoopBook.Close SaveChanges:=True                '// Release object variable                Set wbLoopBook = Nothing            End If        Next File    End With    With Application        .ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True    End WithEnd Sub
來源:https://www.icode9.com/content-1-255301.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Excel應(yīng)用程序?qū)ο?Application對象)及其常用方法基本操作應(yīng)用示例 - 灰太...
Excel VBA解讀(73):添加和刪除工作表——Add方法和Delete方法
如何用vba不打開excel文件讀寫數(shù)據(jù)?
第13章 Excel常用對象
教程 | VBA實現(xiàn)“聚光燈”功能的方法
Excel VBA 入門(1)
更多類似文章 >>
生活服務(wù)
熱點新聞
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服