根据BOM和已存在的文件生成文件列表
在BOM中记录中有物料编码,物料名称,物料规格等,而且依据BOM已经生成了相应的文件,如采购规格书,检验规格书等,这个时候需要获得这些文件的标题,并且生成一个列表,可以使用下面的VBA代码,具体代码如下:
Function IsFileExists(ByVal strFileName As String) As Boolean
If Dir(strFileName, ) <> Empty Then
IsFileExists = True
Else
IsFileExists = False
End If
End Function Sub setname()
Dim I As Integer
Dim J As Integer
Dim pspname As String
Dim pspnumber As String
Dim tstname As String
Dim tstnumber As String
Dim path As String
Dim srcPath As String
Dim srcPath2 As String
Dim headName As String
Dim headName2 As String
Dim txthead As String Dim wordApp As Object
Dim wordDoc As Object
Dim wordArange As Object
Dim wordSelection As Object
Dim ReplaceSign As Boolean Dim Search1 As String
Dim Search2 As String
Dim docPrefix As String
Dim docSuffix As String
Dim rangSize As Integer 'docPrefix = "-PSP"
'docSuffix = "采购规格书.doc"
'Search1 = "电线"
'Search2 = "6000397-PSP"
'rangSize = 200 docPrefix = "-"
docSuffix = "入场检验报告.doc"
Search1 = "高压电源"
Search2 = "6000000-TST"
'Search1 = "AC-DC开关电源"
'Search2 = "6000412-TST"
rangSize = J =
Dim myItem
'myItem = Array(14, 16, 17, 18, 22, 23, 24, 26, 27, 31, 32, 33, 34, 35, 36, 48, 50, 55, 56, 62, 63, 64, 65, 66, 67, 68, 69, 71, 73, 77, 79, 102, 114, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 172, 173, 174, 175, 176, 177, 179, 180, 181)
For I = To
srcPath = "C:\cygwin\tmp\BOM\tst16.doc"
If ActiveSheet.Cells(I, ) = "" Then
headName2 = ActiveSheet.Cells(I, ) & "-" & ActiveSheet.Cells(I, ) & "-" & ActiveSheet.Cells(I, )
headName = headName2 & docSuffix
headName3 = ActiveSheet.Cells(I, )
Else
headName2 = ActiveSheet.Cells(I, ) & "-" & ActiveSheet.Cells(I, ) & "-" & ActiveSheet.Cells(I, )
headName = headName2 & docSuffix
headName3 = ActiveSheet.Cells(I, ) & "(" & ActiveSheet.Cells(I, ) & ")"
End If
headName = Replace(headName, "/", "-")
path = "D:\bom\"
srcPath2 = path & "\aa.doc"
'pspname = path & "\" & ActiveSheet.Cells(I, 3) & docPrefix & ActiveSheet.Cells(I, 4) & docSuffix
pspname = "D:\bom\" & ActiveSheet.Cells(I, ) & "-TST-V1.0.doc"
tstname = "D:\bom\" & ActiveSheet.Cells(I, ) & "-TST-V1.0.doc"
tstnumber = ActiveSheet.Cells(I, ) & "-TST" If IsFileExists(pspname) = True Then
'FileCopy srcPath, srcPath2
'Name srcPath2 As tstname Set wordApp = CreateObject("Word.Application") '建立WORD实例
wordApp.Visible = False '屏蔽WORD实例窗体
Set wordDoc = wordApp.Documents.Open(tstname) '打开文件并赋予文件实例
Set wordSelection = wordApp.Selection '定位文件实例
Set wordArange = wordApp.ActiveDocument.Range(, rangSize) '指定文件编辑位置
wordArange.Select '激活编辑位置 txthead = wordArange
txthead = Application.WorksheetFunction.Clean(txthead)
txthead = Trim(txthead) 'Do
' ReplaceSign = wordArange.Find.Execute("XXX", True, , , , , wdReplaceAll, wdFindContinue, , headName3, True)
'Loop Until ReplaceSign = False 'For Each rngStory In wordDoc.StoryRanges
' Do
' ReplaceSign = rngStory.Find.Execute(Search2, True, , , , , wdReplaceAll, wdFindContinue, , tstnumber, True)
' Set rngStory = rngStory.NextStoryRange
' Loop Until rngStory Is Nothing
'Next wordDoc.Save
wordDoc.Close True
wordApp.Quit
ActiveSheet.Cells(I, ) = tstnumber
ActiveSheet.Cells(I, ) = txthead ActiveSheet.Cells(J, ) = tstnumber
ActiveSheet.Cells(J, ) = txthead
J = J +
End If
Next I End Sub
根据BOM和已存在的文件生成文件列表的更多相关文章
- 递归遍历磁盘下的某一文件夹中所有文件,并copy文件生成文件和带文件夹的文件
package com.hudong.test; import java.io.File; import java.io.IOException; import java.util.ArrayList ...
- java 上传文件-生成文件首页缩略图 生成pdf 抓取图片
方法:1.文件转换成pdf(采用openoffice或者jacob) 2.抓取pdf首页图 第一步:采用jacob: a.下载jacob 注意区分32位,64位,否则不能用 将dll文件放在ja ...
- python 读取文件生成嵌套列表
def read_data(file_name): if not re.findall(".txt", file_name): file_name += ".txt&qu ...
- [工具类]文件或文件夹xx已存在,则重命名为xx(n)(2)
写在前面 最近一直在弄文件传输组件,其中一个功能就是,在接收端接收文件时,如果文件已经存在了,则对其进行文件名+索引的方式进行自动重命名,之前也写个类似的工具类,总感觉代码太冗余,每回头想想,总觉得心 ...
- Ant快速入门(三)-----定义生成文件
适应Ant的关键就是编写生成文件,生成文件定义了该项目的各个生成任务(以target来表示,每个target表示一个生成任务),并定义生成任务之间的依赖关系. Ant生成文件的默认名为build.xm ...
- 由WSDL文件生成WEB service server端C#程序(转)
一般一个已经实现功能的WEB Server会发布自己的WSDL文件,供客户端生成代理类. 但有时是先有的server与client交互的接口定义(WSDL)文件,然后由server和client端分别 ...
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(16)-类库架构扩展以及DLL文件生成修改和用户的简单添加
原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(16)-类库架构扩展以及DLL文件生成修改和用户的简单添加 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) ...
- 项目小程序笔记-登录界面+FPGA管脚分配文件生成
声明:只是为了记录我遇到的一些问题,其中有我理解错的望勿参考. (1)qt designer设计好窗口 主窗口: 登录窗口: 关于qt designer的使用,大可以百度,很简单的,要注意的是部件的参 ...
- linux 平台core dump文件生成
1. 在终端中输入ulimit -c 如果结果为0,说明当程序崩溃时,系统并不能生成core dump. root@hbg:/# ulimit -c0root@hbg:/# 2.使用ulimit -c ...
随机推荐
- PHP 图片生成文字
$dst_path = './1.png'; $font_file = './ADOBEHEITISTD-REGULAR (V5.010).OTF'; $img_bg = imagecreatefro ...
- Maven仓库管理-Nexus
Maven仓库管理-Nexus @import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style& ...
- 【Mail】搭建邮件服务器(LAMP+Postfix+Dovcot+PostfixAdmin+Roundcubemail)
大纲 一.mail部署说明 二.安装准备 三.LMAP环境配置 四.配置postfixadmin 五.配置postfix 六.配置dovecot 七.测试SMTP和POP3服务 八.配置Roundcu ...
- ios6 滤镜相关知识内容网址---摘要
http://blog.csdn.net/justinjing0612/article/details/8145607#
- tomcat详情
[转载]http://grass51.blog.51cto.com/4356355/1123400
- css3 2D动画的基本用法和介绍
<style> body{height:400px;border:1px solid #000;} .box{width:90px;height:30px;border:1px solid ...
- label下面放置select的问题
今天做项目的时候突然发现一个问题. html标签label的用法分两种: <label for="name">姓名:</label><input id ...
- Mac下升级Nodejs
突然发现系统中的nodejs版本比较旧,想升级一下但又不想下载安装包一步一步安装, 发现还是可以很简单用命令行升级的. 首先得清理npm的缓存 sudo npm cache clean -f 安装 n ...
- if else 的令人防不胜防的奇葩错误
if(a==t && b+c >a) else flag=false; 这个语句乍一看没什么问题,如果a==t 成立b+c >a不成立-〉flag=false; 但是编译 ...
- c++中的指针之指针在数组
使用一维指针数组输出一维数组中的数 int array[]={1,2,3,4,5,6}; int *p; p=array; for(int i=0;i<6;i++){ ...