1000以上のレコードと100万件近くのレコードを含む約40のブックがあります。Excel:複数のブックの数値形式にテキストを変換する方法
残念ながら、ほとんどのデータはテキスト形式でインポートされており、特定の列を数値形式に変換しようとしています。
貼り付けスペシャル>掛け算テクニックを使ってすべてのファイルを手動で編集する以外に、特定のフォルダ内のすべてのExcelファイルを繰り返し処理する方法がありますか?
1000以上のレコードと100万件近くのレコードを含む約40のブックがあります。Excel:複数のブックの数値形式にテキストを変換する方法
残念ながら、ほとんどのデータはテキスト形式でインポートされており、特定の列を数値形式に変換しようとしています。
貼り付けスペシャル>掛け算テクニックを使ってすべてのファイルを手動で編集する以外に、特定のフォルダ内のすべてのExcelファイルを繰り返し処理する方法がありますか?
変更する列と数値が分かります。あなたはそれのマクロを記録し、この基本的なDIR()技術にそれを挿入することができます。
Option Explicit
Sub LoopThroughFolder()
Dim fPATH As String, fNAME As String
Dim wb As Workbook
fPATH = "C:\Path\To\My\Files\" 'remember the final \
fNAME = Dir(fPATH & "*.xl*") 'get first filename from fPATH
Application.ScreenUpdating = False 'speed up execution
Do While Len(fNAME) > 0
Set wb = Workbooks.Open(fPATH & fNAME)
'your code here to format that activesheet
wb.Close True 'save and close the edited file
fNAME = Dir 'get the next filename
Loop
Application.ScreenUpdating = True
End Sub
Option Compare Database
Public Function format(filepath, sheetname, sheetpath)
Set xls = CreateObject("EXCEL.APPLICATION")
xls.screenupdating = False
xls.displayalerts = False
xls.Visible = True
xls.workbooks.Open filepath
Set xlsdd = xls.ActiveWorkbook
'deleting headers
xls.Range("1:1").Select
xls.Selection.Delete Shift:=xlUp
'adding one column
xls.Columns("A:A").Select
xls.Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
'adding 5 rows
'ActiveWorkbook.Sheets("sheet1").Select
xls.Rows("1:5").Insert Shift:=xlDown
' fetching rows from access and putting them into excel
' strsql = "select top 5 " & sheetname & ".* into top5_records from " & sheetname
' DoCmd.RunSQL strsql
' outputFileName = "C:\Users\hp\Desktop\top5_records.xls"
' DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "top5_records", outputFileName, True
'then open that excel and copy the rows
Set xls2 = CreateObject("EXCEL.APPLICATION")
xls2.screenupdating = False
xls2.displayalerts = False
xls2.Visible = True
xls2.workbooks.Open sheetpath
Set xlsdd2 = xls2.ActiveWorkbook
xls2.Rows("1:5").Select
xls2.Selection.Copy
xls.Cells(1, 1).Select
xls.activesheet.Paste
'making first 6th row to be bold
xls.Rows("6:6").Select
With xls.Selection.Font
.Bold = True
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
End With
'autofit the data
xls.Sheets(sheetname).Cells.Columns.autofit
xls.CutCopyMode = False
'making both the excel objects to be free
With xlsdd
.Save
.Close
End With
xls.Visible = False
Set xlsdd = Nothing
Set xls = Nothing
With xlsdd2
.Save
.Close
End With
xls2.Visible = False
Set xlsdd2 = Nothing
Set xls2 = Nothing
End Function
は、この[私の答え]を参照して、特定のフォルダ内のすべてのExcelファイルを反復処理する(のhttp:// stackoverflow.com/a/9864075/973283)。 –