VBA唏嘘戏——简单单元格的设定(实例)

由于有很多个Word文件,所以应用宏会更加方便排版,而且版式较为统一。

Sub 设置列宽()
‘
‘  设置列宽宏
‘
‘
    ActiveDocument.Tables(1).Cell(7, 2).Width = 45   ‘将Word表格的第7行第2列(即B7单元格)的宽度设为45
    ActiveDocument.Tables(1).Cell(7, 3).Width = 30
    ActiveDocument.Tables(1).Cell(7, 4).Width = 117
    ActiveDocument.Tables(1).Cell(7, 5).Width = 33
    ActiveDocument.Tables(1).Cell(7, 6).Width = 30
    ActiveDocument.Tables(1).Cell(7, 7).Width = 30
    ActiveDocument.Tables(1).Cell(7, 8).Width = 30
    ActiveDocument.Tables(1).Cell(7, 9).Width = 57
    ActiveDocument.Tables(1).Cell(7, 10).Width = 39
    ActiveDocument.Tables(1).Cell(7, 11).Width = 39
    ActiveDocument.Tables(1).Cell(7, 12).Width = 60
    ActiveDocument.Tables(1).Cell(7, 13).Width = 33
    ActiveDocument.Tables(1).Cell(7, 14).Width = 30
    ActiveDocument.Tables(1).Cell(7, 15).Width = 30
    ActiveDocument.Tables(1).Cell(7, 16).Width = 30
    ActiveDocument.Tables(1).Cell(7, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(7, 17).Range.Text = ""  ‘将Word的表格第7行第17列单元格(Q7单元格)的值设置为空

    ActiveDocument.Tables(1).Cell(8, 2).Width = 45
    ActiveDocument.Tables(1).Cell(8, 3).Width = 30
    ActiveDocument.Tables(1).Cell(8, 4).Width = 117
    ActiveDocument.Tables(1).Cell(8, 5).Width = 33
    ActiveDocument.Tables(1).Cell(8, 6).Width = 30
    ActiveDocument.Tables(1).Cell(8, 7).Width = 30
    ActiveDocument.Tables(1).Cell(8, 8).Width = 30
    ActiveDocument.Tables(1).Cell(8, 9).Width = 57
    ActiveDocument.Tables(1).Cell(8, 10).Width = 39
    ActiveDocument.Tables(1).Cell(8, 11).Width = 39
    ActiveDocument.Tables(1).Cell(8, 12).Width = 60
    ActiveDocument.Tables(1).Cell(8, 13).Width = 33
    ActiveDocument.Tables(1).Cell(8, 14).Width = 30
    ActiveDocument.Tables(1).Cell(8, 15).Width = 30
    ActiveDocument.Tables(1).Cell(8, 16).Width = 30
    ActiveDocument.Tables(1).Cell(8, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(8, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(9, 2).Width = 45
    ActiveDocument.Tables(1).Cell(9, 3).Width = 30
    ActiveDocument.Tables(1).Cell(9, 4).Width = 117
    ActiveDocument.Tables(1).Cell(9, 5).Width = 33
    ActiveDocument.Tables(1).Cell(9, 6).Width = 30
    ActiveDocument.Tables(1).Cell(9, 7).Width = 30
    ActiveDocument.Tables(1).Cell(9, 8).Width = 30
    ActiveDocument.Tables(1).Cell(9, 9).Width = 57
    ActiveDocument.Tables(1).Cell(9, 10).Width = 39
    ActiveDocument.Tables(1).Cell(9, 11).Width = 39
    ActiveDocument.Tables(1).Cell(9, 12).Width = 60
    ActiveDocument.Tables(1).Cell(9, 13).Width = 33
    ActiveDocument.Tables(1).Cell(9, 14).Width = 30
    ActiveDocument.Tables(1).Cell(9, 15).Width = 30
    ActiveDocument.Tables(1).Cell(9, 16).Width = 30
    ActiveDocument.Tables(1).Cell(9, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(9, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(10, 2).Width = 45
    ActiveDocument.Tables(1).Cell(10, 3).Width = 30
    ActiveDocument.Tables(1).Cell(10, 4).Width = 117
    ActiveDocument.Tables(1).Cell(10, 5).Width = 33
    ActiveDocument.Tables(1).Cell(10, 6).Width = 30
    ActiveDocument.Tables(1).Cell(10, 7).Width = 30
    ActiveDocument.Tables(1).Cell(10, 8).Width = 30
    ActiveDocument.Tables(1).Cell(10, 9).Width = 57
    ActiveDocument.Tables(1).Cell(10, 10).Width = 39
    ActiveDocument.Tables(1).Cell(10, 11).Width = 39
    ActiveDocument.Tables(1).Cell(10, 12).Width = 60
    ActiveDocument.Tables(1).Cell(10, 13).Width = 33
    ActiveDocument.Tables(1).Cell(10, 14).Width = 30
    ActiveDocument.Tables(1).Cell(10, 15).Width = 30
    ActiveDocument.Tables(1).Cell(10, 16).Width = 30
    ActiveDocument.Tables(1).Cell(10, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(10, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(11, 2).Width = 45
    ActiveDocument.Tables(1).Cell(11, 3).Width = 30
    ActiveDocument.Tables(1).Cell(11, 4).Width = 117
    ActiveDocument.Tables(1).Cell(11, 5).Width = 33
    ActiveDocument.Tables(1).Cell(11, 6).Width = 30
    ActiveDocument.Tables(1).Cell(11, 7).Width = 30
    ActiveDocument.Tables(1).Cell(11, 8).Width = 30
    ActiveDocument.Tables(1).Cell(11, 9).Width = 57
    ActiveDocument.Tables(1).Cell(11, 10).Width = 39
    ActiveDocument.Tables(1).Cell(11, 11).Width = 39
    ActiveDocument.Tables(1).Cell(11, 12).Width = 60
    ActiveDocument.Tables(1).Cell(11, 13).Width = 33
    ActiveDocument.Tables(1).Cell(11, 14).Width = 30
    ActiveDocument.Tables(1).Cell(11, 15).Width = 30
    ActiveDocument.Tables(1).Cell(11, 16).Width = 30
    ActiveDocument.Tables(1).Cell(11, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(11, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(12, 2).Width = 45
    ActiveDocument.Tables(1).Cell(12, 3).Width = 30
    ActiveDocument.Tables(1).Cell(12, 4).Width = 117
    ActiveDocument.Tables(1).Cell(12, 5).Width = 33
    ActiveDocument.Tables(1).Cell(12, 6).Width = 30
    ActiveDocument.Tables(1).Cell(12, 7).Width = 30
    ActiveDocument.Tables(1).Cell(12, 8).Width = 30
    ActiveDocument.Tables(1).Cell(12, 9).Width = 57
    ActiveDocument.Tables(1).Cell(12, 10).Width = 39
    ActiveDocument.Tables(1).Cell(12, 11).Width = 39
    ActiveDocument.Tables(1).Cell(12, 12).Width = 60
    ActiveDocument.Tables(1).Cell(12, 13).Width = 33
    ActiveDocument.Tables(1).Cell(12, 14).Width = 30
    ActiveDocument.Tables(1).Cell(12, 15).Width = 30
    ActiveDocument.Tables(1).Cell(12, 16).Width = 30
    ActiveDocument.Tables(1).Cell(12, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(12, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(13, 2).Width = 45
    ActiveDocument.Tables(1).Cell(13, 3).Width = 30
    ActiveDocument.Tables(1).Cell(13, 4).Width = 117
    ActiveDocument.Tables(1).Cell(13, 5).Width = 33
    ActiveDocument.Tables(1).Cell(13, 6).Width = 30
    ActiveDocument.Tables(1).Cell(13, 7).Width = 30
    ActiveDocument.Tables(1).Cell(13, 8).Width = 30
    ActiveDocument.Tables(1).Cell(13, 9).Width = 57
    ActiveDocument.Tables(1).Cell(13, 10).Width = 39
    ActiveDocument.Tables(1).Cell(13, 11).Width = 39
    ActiveDocument.Tables(1).Cell(13, 12).Width = 60
    ActiveDocument.Tables(1).Cell(13, 13).Width = 33
    ActiveDocument.Tables(1).Cell(13, 14).Width = 30
    ActiveDocument.Tables(1).Cell(13, 15).Width = 30
    ActiveDocument.Tables(1).Cell(13, 16).Width = 30
    ActiveDocument.Tables(1).Cell(13, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(13, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(14, 2).Width = 45
    ActiveDocument.Tables(1).Cell(14, 3).Width = 30
    ActiveDocument.Tables(1).Cell(14, 4).Width = 117
    ActiveDocument.Tables(1).Cell(14, 5).Width = 33
    ActiveDocument.Tables(1).Cell(14, 6).Width = 30
    ActiveDocument.Tables(1).Cell(14, 7).Width = 30
    ActiveDocument.Tables(1).Cell(14, 8).Width = 30
    ActiveDocument.Tables(1).Cell(14, 9).Width = 57
    ActiveDocument.Tables(1).Cell(14, 10).Width = 39
    ActiveDocument.Tables(1).Cell(14, 11).Width = 39
    ActiveDocument.Tables(1).Cell(14, 12).Width = 60
    ActiveDocument.Tables(1).Cell(14, 13).Width = 33
    ActiveDocument.Tables(1).Cell(14, 14).Width = 30
    ActiveDocument.Tables(1).Cell(14, 15).Width = 30
    ActiveDocument.Tables(1).Cell(14, 16).Width = 30
    ActiveDocument.Tables(1).Cell(14, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(14, 17).Range.Text = ""

    ActiveDocument.Tables(1).Cell(15, 2).Width = 45
    ActiveDocument.Tables(1).Cell(15, 3).Width = 30
    ActiveDocument.Tables(1).Cell(15, 4).Width = 117
    ActiveDocument.Tables(1).Cell(15, 5).Width = 33
    ActiveDocument.Tables(1).Cell(15, 6).Width = 30
    ActiveDocument.Tables(1).Cell(15, 7).Width = 30
    ActiveDocument.Tables(1).Cell(15, 8).Width = 30
    ActiveDocument.Tables(1).Cell(15, 9).Width = 57
    ActiveDocument.Tables(1).Cell(15, 10).Width = 39
    ActiveDocument.Tables(1).Cell(15, 11).Width = 39
    ActiveDocument.Tables(1).Cell(15, 12).Width = 60
    ActiveDocument.Tables(1).Cell(15, 13).Width = 33
    ActiveDocument.Tables(1).Cell(15, 14).Width = 30
    ActiveDocument.Tables(1).Cell(15, 15).Width = 30
    ActiveDocument.Tables(1).Cell(15, 16).Width = 30
    ActiveDocument.Tables(1).Cell(15, 17).Width = 70.5
    ActiveDocument.Tables(1).Cell(15, 17).Range.Text = ""

    ActiveDocument.Tables(1).AllowAutoFit = False

End Sub

时间: 2024-08-02 14:52:32

VBA唏嘘戏——简单单元格的设定(实例)的相关文章

在Excel里用vba给合并的单元格添加注释

Excel里使用VBA对已经合并的单元格添加注释,直接使用AddComment会报: 运行时错误 '1004':应用程序定义或者对象定义错误 找了很多文章都没找到怎么解决,最后发现在AddComment之前,先ClearComments一下,就好了 Excel using vba to add comment to a merged cell if occur runtime error 1004, before invoking addcomment, first  invoke ClearC

jquery实现的拖动可以调整table单元格大小代码实例

jquery实现的拖动可以调整table单元格大小代码实例: 本章节介绍一下如果利用jquery实现表格单元格可以通过鼠标拖动调整大小的效果,当然如果让我们完全写代码的话,可能会比较的复杂,不过有现成的插件可以使用,只要简单的几个步骤就可以实现我们的要求. 一.引入相关库文件: 要使用相关插件,那就必须要引入相关的代码文件,如下: <script src="/js/jquery-1.8.0.min.js" type="text/javascript">&

VBA学习笔记之单元格

'单元格对象在VBA中一个非常基础,同时也很重要的. '它的表达方式也是非常的多样化. '---------------------------------------------------- 'Range 对象 '代表某一单元格.某一行.某一列.某一选定区域(该区域可包含一个或若干连续单元格区域),或者某一三维区域. 'Range ("文本型装单元格地址") 'range的常见写法 Sub rng() Range("a1").Select '单元格 Range(

VBA学习笔记之单元格查询系统制作

1 Sub 自己写查询系统() 2 end_num = Columns(1).Find("*", searchdirection:=xlPrevious).Row '动态找到A列的最后一个单元格 3 k = 1 4 m = 1 5 Range(Cells(3, "h"), Cells(999, "l")).Clear 6 For Each Rng In Range("a2:" & "a" &

使用VBA将Excel指定单元格数据、字符串或者图表对象插入到Word模板指定书签处

准备工作: 1.首先需要提供一个word模板,并且标记好您要插入书签的位置,定义书签的命名.如图 2.模拟您要插入的Excel原始数据和图表对象 插入代码如下: Private Sub CommandButton1_Click() Dim App, WrdDoc, Mypath As String On Error Resume Next '定义原始模板的储存路径,默认和excel在同一路径 Mypath = ThisWorkbook.Path & "\模板.doc" '用Se

报表设计--单元格公式-设置实例

一.新建数据源 二.操作步骤 在A1单元格中填写=To(1,4)设置纵向扩展 在B1单元格中填写=To(5,10)设置纵向扩展 在C1单元格中填写=A1*B1 在D1单元格中填写=B1+C1 在C2单元格中填写=sum(c1{})  表示求C1的小计 在C3单元格中填写=sum(c1{})  表示求C1的合计(支持中文状态的大括号) 在E1单元格中填写=Sum(list(b1,c1,d1))  表示求b1,c1,d1单元格的和 在E2单元格中填写=SUM(E1{})  表示求E1的和 在E3单元

对简单单元格的增删改

效果图 #import <UIKit/UIKit.h> #import "RootTableViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end #import "AppDelegate.h" @interface AppDelegat

VBA对指定单元格填充颜色并且赋值

使用VBA对指定的单元格赋值并填充颜色 ====================================================== 代码区域 ====================================================== Sub row应用() For Each rw In Rows("1:13") If rw.Row Mod 2 = 0 Then rw.Interior.ColorIndex = 3 rw.Value = 99 End

c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)

一.单元格内容的操作 *****// 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index       Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex); // 取得当前单元格的行 Index       Console.WriteLine(DataGridView1.CurrentCell.RowIndex); ******