ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 2614|回复: 6

[求助]【紧急求助】守柔版主!关于程序自动化的问题!在线等待!麻烦你!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-2-14 13:04 | 显示全部楼层 |阅读模式
[求助]【紧急求助】守柔版主!关于程序自动化的问题!在线等待!麻烦你! 等待中!!! 5cUnvyFs.rar (21.3 KB, 下载次数: 23)
[此贴子已经被作者于2006-2-14 15:42:28编辑过]

TA的精华主题

TA的得分主题

发表于 2006-2-14 15:14 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
以下是引用[I]taipei-joe[/I]在2006-2-14 13:04:39的发言:[BR][求助]【紧急求助】雨柔版主!关于程序自动化的问题!在线等待!麻烦你! 等待中!!!
“雨柔”?是谁啊? 不会是守柔版主吧?

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-2-14 15:31 | 显示全部楼层
不好意思!打错了!马上改!谢谢!

TA的精华主题

TA的得分主题

发表于 2006-2-14 18:27 | 显示全部楼层

这几天我很忙,抽空做了一个示例,请楼主测试一下,另外,按月打印是否与其它项目有关,比如期数后按月?你的数据多不多,可能需要重新考虑程序问题。

Private Sub CommandButton1_Click()
Dim WdApp As Word.Application, WdDoc As Word.Document, I As Byte, myRange As Range
Dim Firstrange As String, LastRange As String, a As Range, M As Byte, N As Byte, TF As Boolean
Dim Msg, Style, Title, Help, Ctxt, Response, MyString, wdRange As Word.Range
Dim myArray() As String, L As Integer, aTable As Word.Table, aCell As Word.Cell
With Sheets(1)
LastRange = .[A65536].End(xlUp).Address
Set myRange = .Range("A3:" & LastRange)
MyString = VBA.InputBox("ÇëÊäÈëÐèÒª´òÓ¡µÄÖ¸¶¨ÆÚÊý!", Title:="Excel_Word", Default:=1)
If MyString = "" Then Exit Sub
MyString = VBA.Val(MyString)
MyString = VBA.Format(MyString, "0000")
Set a = myRange.Find(What:=MyString, LookIn:=xlValues, LookAt:=xlWhole)
If a Is Nothing Then
MsgBox "ExcelδÔÚÖ¸¶¨µÄÁÐÖвéÕÒµ½¸ÃÆÚÊýÖµ,ÇëÈ·ÈÏ!", vbInformation + vbOKOnly
Exit Sub
Else
Set myRange = .Range(a.Address & ":" & LastRange)
End If
End With
On Error Resume Next 'ºöÂÔ´íÎó
Application.ScreenUpdating = False '¹Ø±ÕÆÁÄ»¸üÐÂ
Set WdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
TF = True
Set WdApp = CreateObject("Word.Application") '´´½¨Ò»¸öWORD³ÌÐò
End If
Set WdDoc = WdApp.Documents.Open(ThisWorkbook.Path & "\ÆÚÊý.dot")
WdApp.Visible = True
With WdDoc
I = 1 '³õʼ»¯±äÁ¿
For Each a In myRange
Set wdRange = .Range(.Content.End - 1, .Content.End - 1)
If I > 20 Or I = 1 Then
ReDim Preserve myArray(L)
myArray(L) = "ÊÕÊÓÂÊ": L = L + 1
I = 1: N = N + 1 'I³õʼ»¯,NÖµÀÛ¼Ó
.AttachedTemplate.AutoTextEntries("ÆÚÊý").Insert where:=wdRange, RichText:=True
End If
ReDim Preserve myArray(L)
myArray(L) = VBA.Format(a.Offset(, 5), "Percent")
L = L + 1
With .Tables(N)
For M = 1 To 5
Select Case M
Case 1
.Cell(I + 1, M).Range = VBA.Format(a.Offset(, M - 1).Value, "0000")
Case 4
.Cell(I + 1, M).Range = VBA.Format(a.Offset(, M - 1).Value, "YYYYÄêMMÔÂDDÈÕ aaaa")
Case Else
.Cell(I + 1, M).Range = a.Offset(, M - 1).Value
End Select
Next M
End With
I = I + 1 'ÀÛ¼Ó
Next
Application.ScreenUpdating = True '»Ö¸´ÆÁÄ»¸üÐÂ
WdApp.Visible = True
Msg = "Îĵµ¸ñʽΪ¡º¡ù¡ù¡ù¡ù¡ù¡»×¨Êô¹«¸æ¸ñʽ£¬ÈçÐèÐ޸ģ¬Çë֪ͨÏà³ÌÐò¿ª·¢¹ØÈËÔ±ÐÞÕý£¡ÊÇ·ñ¿ªÊ¼´òÓ¡£¿"
Style = vbYesNo + vbCritical + vbDefaultButton1 ' ¶¨Òå°´Å¥¡£
Ctxt = 1000
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' Óû§°´Ï¡°ÊÇ¡±¡£
If MsgBox("ÊÇ·ñÐèÒª½«½ø¶ÈÊý¾ÝÐÞ¸ÄΪÊÕÊÓÂʵÄÊý¾Ý?", vbYesNo + vbDefaultButton2) = vbYes Then
L = 0
For Each aTable In .Tables
For Each aCell In aTable.Columns(5).Cells
aCell.Range = myArray(L)
L = L + 1
Next
Next
.PrintOut
End If
End If
.Close False
End With
If TF = True Then WdApp.Quit
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-2-15 01:11 | 显示全部楼层
守柔版主!你给我的代码是乱码!是否可以用附件给我程式码??谢谢!

TA的精华主题

TA的得分主题

发表于 2006-2-15 06:22 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
以下是引用[I]taipei-joe[/I]在2006-2-15 1:11:44的发言:
守柔版主!你给我的代码是乱码!是否可以用附件给我程式码??谢谢!
我这才注意到,楼主提问及回复的语气中多是感叹号,我不知楼主哪来的这么的感叹! 我同时也注意到,楼主所说的乱码,是代码粘贴过程中经常出现的问题,但我目前改用WINXP+WORD2003却是首次,首先向楼主说声抱歉,我没有检查一下回复的贴子。 我更注意到,楼主对于我的提问,没有回答,对于代码,,你只要把代码中的自动图文集名称修改一下,其它的对话框中的中文根本不影响代码处理的思路,所以……,我把代码重新粘贴一次。 '* +++++++++++++++++++++++++++++ '* Created By I LOVE YOU WORD!@ExcelHome 2006-2-15 6:21:56 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0009^The Code CopyIn [Excel-SHEET1]^' '* ----------------------------- Option Explicit Private Sub CommandButton1_Click() Dim WdApp As Word.Application, WdDoc As Word.Document, I As Byte, myRange As Range Dim Firstrange As String, LastRange As String, a As Range, M As Byte, N As Byte, TF As Boolean Dim Msg, Style, Title, Help, Ctxt, Response, MyString, wdRange As Word.Range Dim myArray() As String, L As Integer, aTable As Word.Table, aCell As Word.Cell With Sheets(1) LastRange = .[A65536].End(xlUp).Address Set myRange = .Range("A3:" & LastRange) MyString = VBA.InputBox("请输入需要打印的指定期数!", Title:="Excel_Word", Default:=1) If MyString = "" Then Exit Sub MyString = VBA.Val(MyString) MyString = VBA.Format(MyString, "0000") Set a = myRange.Find(What:=MyString, LookIn:=xlValues, LookAt:=xlWhole) If a Is Nothing Then MsgBox "Excel未在指定的列中查找到该期数值,请确认!", vbInformation + vbOKOnly Exit Sub Else Set myRange = .Range(a.Address & ":" & LastRange) End If End With On Error Resume Next '忽略错误 Application.ScreenUpdating = False '关闭屏幕更新 Set WdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Err.Clear TF = True Set WdApp = CreateObject("Word.Application") '创建一个WORD程序 End If Set WdDoc = WdApp.Documents.Open(ThisWorkbook.Path & "\期数.dot") WdApp.Visible = True With WdDoc I = 1 '初始化变量 For Each a In myRange Set wdRange = .Range(.Content.End - 1, .Content.End - 1) If I > 20 Or I = 1 Then ReDim Preserve myArray(L) myArray(L) = "收视率": L = L + 1 I = 1: N = N + 1 'I初始化,N值累加 .AttachedTemplate.AutoTextEntries("期数").Insert where:=wdRange, RichText:=True End If ReDim Preserve myArray(L) myArray(L) = VBA.Format(a.Offset(, 5), "Percent") L = L + 1 With .Tables(N) For M = 1 To 5 Select Case M Case 1 .Cell(I + 1, M).Range = VBA.Format(a.Offset(, M - 1).Value, "0000") Case 4 .Cell(I + 1, M).Range = VBA.Format(a.Offset(, M - 1).Value, "YYYY年MM月DD日 aaaa") Case Else .Cell(I + 1, M).Range = a.Offset(, M - 1).Value End Select Next M End With I = I + 1 '累加 Next Application.ScreenUpdating = True '恢复屏幕更新 WdApp.Visible = True Msg = "文档格式为『※※※※※』专属公告格式,如需修改,请通知相程序开发关人员修正!是否开始打印?" Style = vbYesNo + vbCritical + vbDefaultButton1 ' 定义按钮。 Ctxt = 1000 Response = MsgBox(Msg, Style, Title, Help, Ctxt) If Response = vbYes Then ' 用户按下“是”。 If MsgBox("是否需要将进度数据修改为收视率的数据?", vbYesNo + vbDefaultButton2) = vbYes Then L = 0 For Each aTable In .Tables For Each aCell In aTable.Columns(5).Cells aCell.Range = myArray(L) L = L + 1 Next Next .PrintOut End If End If .Close False End With If TF = True Then WdApp.Quit End Sub
[此贴子已经被作者于2006-2-15 6:23:08编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-2-15 11:08 | 显示全部楼层

谢谢你守柔版主!

惊叹号是打字的习惯,并没有任何意义。造成你的误解,真不好意思。

至于所说的按月份打印,是利用日期栏来查询月份,昨天晚上我看过你的程式码后,我觉得应该可以用case 4中的“VBA.Format(a.Offset(, M - 1).Value, "YYYY年MM月DD日 aaaa")”去查出月份文件所需的月份,然后打印,我先试试,如果真的搞不定,再次请教你!

再次谢谢你!

[此贴子已经被作者于2006-2-15 11:08:46编辑过]
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-16 05:28 , Processed in 0.038683 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表