本文介绍了代码生成错误1004方法对象范围失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码是从Excel宏生成的。我粘贴到Access中,它在第一次传递时运行正常,但后续运行失败。

This code was generated from an Excel macro. I pasted into Access and it runs fine on the first pass but subsequent runs fail.

我不清楚如何限定代码以使其通过多次执行运行。

I am not clear how to qualify the code to get it to run thru several executions.

公共函数runExcelMacro(wkbookPath,wsname)

Public Function runExcelMacro(wkbookPath, wsname)

Dim xl As Excel.Application

Dim xl As Excel.Application

Dim wb As Excel.Workbook

Dim wb As Excel.Workbook

Dim ws As Excel.Worksheet

Dim ws As Excel.Worksheet

设置xl = CreateObject(" Excel.Application")

Set xl = CreateObject("Excel.Application")

设置wb = xl.Workbooks.Open(wkbookPath )

Set wb = xl.Workbooks.Open(wkbookPath)

设置ws = wb.Worksheets(wsname)

Set ws = wb.Worksheets(wsname)

wb.CheckCompatibility = False

wb.CheckCompatibility = False

   &nb的SP;
范围("A1:O1")。选择

   
使用Selection.Interior

    With Selection.Interior

      ;  
.Pattern = xlSolid

       .Pattern = xlSolid

      ;  
.PatternColorIndex = xlAutomatic

       .PatternColorIndex = xlAutomatic

      ;  
.Color = 65535

       .Color = 65535

      ;  
.TintAndShade = 0

       .TintAndShade = 0

      ;  
.PatternTintAndShade = 0

       .PatternTintAndShade = 0

   
结束

   
ActiveWorkbook.Save

    ActiveWorkbook.Save

wb.Saved = True

wb.Saved = True

wb.CheckCompatibility = True

wb.CheckCompatibility = True

xl .Workbooks.Close

xl.Workbooks.Close

xl.Application.Quit

xl.Application.Quit

Set wb = Nothing

Set wb = Nothing

Set xl = NothingEnd Function

Set xl = NothingEnd Function

推荐答案

Range(" A1:O1")。选择

应该

ws.Range(" A1:O1")。选择


这篇关于代码生成错误1004方法对象范围失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:10