简体   繁体   English

使用条件格式将导出文件从 access 格式化为 excel

[英]Formatting an export file from access to excel with conditional formatting

Needing assistance on performing a format check.在执行格式检查时需要帮助。 Ok so what I have now is a button on my access form that exports the results into a new blank Excel file when clicked.好的,我现在拥有的是访问表单上的一个按钮,单击该按钮将结果导出到一个新的空白 Excel 文件中。 What I am trying to accomplish now is add some code that checks if Fields 6-10 added together <> field 5 throughout the WHOLE dataset then performing conditional formatting and highlight the ones that aren't the same as yellow.我现在想要完成的是添加一些代码来检查字段 6-10 是否在整个 WHOLE 数据集中添加在一起 ​​<> 字段 5 然后执行条件格式并突出显示与黄色不同的那些。

Once this is in place, Then I would like a message box to appear and however many items that are highlighted in the Excel file to appear within the list box msg.一旦到位,然后我希望出现一个消息框,并且在 Excel 文件中突出显示的许多项目出现在列表框 msg 中。 An example being there are (9) cells that are mismatched and need attention before an upload can be submitted!"例如,有 (9) 个不匹配的单元格需要注意才能提交上传!”

Dim dbs As DAO.Database
Dim Excel_App As Excel.Application 'Creates Blank Excel File
Dim strTable As String ' Table in access
    Dim queryDelete As String 'SQL to delete records in local table
    Dim strAssigned As DAO.Recordset


    strTable = "Make_allUp" 'Access Table I am trying to copy
    Set Excel_App = CreateObject("Excel.Application")
        Set dbs = CurrentDb

Dim rs As DAO.Recordset
Set rs = dbs.OpenRecordset(strTable)

    Excel_App.Visible = True

Dim wkb As Excel.Workbook
Set wkb = Excel_App.Workbooks.Add

Dim rg As Excel.Range
Dim i As Long
' Add the headings
For i = 0 To rs.Fields.Count - 1
    wkb.Sheets(1).Cells(1, i + 1).Value = rs.Fields(i).Name
Next i

Set rg = wkb.Sheets(1).Cells(2, 1)
rg.CopyFromRecordset rs

' make pretty
rg.CurrentRegion.EntireColumn.AutoFit

If wkb.Sheets(1).Cells(5, 2) <> wkb.Sheets(1).Cells(6, 2) + wkb.Sheets(1).Cells(7, 2) + wkb.Sheets    (1).Cells(8, 2) + wkb.Sheets(1).Cells(9, 2) + wkb.Sheets(1).Cells(10, 2) Then
Format.Cells
****Okay above is what I am having troubles with. Just needing to somehow say if the vaule in field 6 + field 7 + field 8 + field 9 + field 10 <> field 5 Then
highlight those records yellow



Set rs = Nothing
Set wkb = Nothing
Set dbs = Nothing


End Sub

As I know, Access will not, and can not, format the export information.据我所知,Access 不会也不能格式化导出信息。 It is possible to write Excel VBA code to format the cells in the target spreadsheet.可以编写 Excel VBA 代码来格式化目标电子表格中的单元格。 Also, it is possible to write code in Access VBA to write the Excel VBA code to format the cells and to have the code exported tot he spreadsheet.此外,可以在 Access VBA 中编写代码来编写 Excel VBA 代码来格式化单元格并将代码导出到电子表格。 In addition, it is also possible to open the spreadsheet where the information was exported and format the cells from within Ms. Access using Access VBA code.此外,还可以打开导出信息的电子表格,并使用 Access VBA 代码从 Ms. Access 中设置单元格格式。 But, as I know, you cannot get Access to format the information prior to, or during, the export process itself.但是,据我所知,在导出过程本身之前或过程中,您无法获得 Access 来格式化信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM