Dim db As DAO.Database
Set db = CurrentDb()
Dim FileNameBase As String
FileNameBase = CurrentProject.path & "\YourExcelSheetName ".xlsx"
Dim strFileName As String
strFileName = Replace(FileNameBase, "[CurrentDate]", Format$(Date, "m-dd-yyyy"))
'---Exporting from Ms Access table to an Excel worksheet
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "TableName1", strFileName, True, "Sheet_One_Name_You_Want"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "TableName2", strFileName, True, "Sheet_Two_Name_You_Want"
'--------------Open that excel sheet and here you do all modification-----------------------------------
Dim appExcel1 As Excel.Application
Dim wbk1 As Excel.Workbook
Dim wks As Excel.Worksheet
Dim rng As Excel.Range
Set appExcel1 = Excel.Application
appExcel1.Visible = True
Set wbk1 = appExcel1.Workbooks.Open(strFileName)
appExcel1.ScreenUpdating = False
' -----------------------------------Formatting Sheet_One_Name_You_Want Sheet -------------------
Sheets("Sheet_One_Name_You_Want").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Columns.AutoFit
Range(Selection, Selection.End(xlToRight)).Columns.AutoFit
Range(Selection, Selection.End(xlDown)).HorizontalAlignment = xlLeft
Range(Selection, Selection.End(xlToRight)).HorizontalAlignment = xlLeft
Range("A1:AK1").RowHeight = 30
Range("A1:AK1").ColumnWidth = 15
Range("A1:AK1").Font.Bold = True
Range("A1:AK1").WrapText = True
Range("A1:AK1").VerticalAlignment = Excel.Constants.xlCenter
'---------------Coloring-----------------
Range("A1:B1").Select
Selection.Interior.ColorIndex = 33
Range("C1").Select
Selection.Interior.ColorIndex = 27
Range("D1").Select
Selection.Interior.ColorIndex = 45
'--------------Change Data type to Currency Format for a Particular column--------------
Range("F2:F100").Select
Selection.Style = "Currency"
'------------------FreezePanes for a Particular column--------------
Range("C1").Select
wbk1.Application.ActiveWindow.FreezePanes = True
END Sub
Tuesday, 8 May 2018
How to open an excel sheet through a MS Access Button and do it modification.
Border Line for a filled cell in Excel VBA.
Once a time I was trying to create a report on excel through MS ACCESS vba. At that time I was really wanted to keep the border for all filled cells. I got a user define function from a browsing web page and it was really helpful. You can modify this function according to your requirement.
Execution Process :
Call this function inside your button just like a - call TheBorderLine or just put TheBorderLine.
Make sure that your workbook is open while calling this function.
Sub TheBorderLine()With ActiveSheet.UsedRange.Borders.LineStyle =xlContinuous.Weight = xlThin.ColorIndex = xlAutomaticEnd WithWith ActiveSheet.Cells.Font.Size ="10"ActiveSheet.Cells.HorizontalAlignment = xlLeftEnd WithRange("A1:S1").SelectWith Selection.HorizontalAlignment = xlCenter.VerticalAlignment = xlCenterEnd WithEnd Sub
Call this function inside your button just like a - call TheBorderLine or just put TheBorderLine.
Make sure that your workbook is open while calling this function.
Subscribe to:
Posts (Atom)