[英]How to do single button action for multi sheet (tabs) excel using VB script?
I am a beginner in VB script and I have a excel sheet with multi tab .我是 VB 脚本的初学者,我有一个带有多选项卡的 excel 表。 I have created a one button inside one excel sheet .
我在一张 Excel 表中创建了一个按钮。 Another sheets having some table .
另一张有一些桌子的床单。 I want to generate some code inside a file with those excel tables using a simple button .
我想使用一个简单的按钮在带有这些 excel 表的文件中生成一些代码。
For example :例如 :
This excel book have one tab called Generate .这本 excel 书有一个名为 Generate 的选项卡。 Inside Generate i have created one button .
在 Generate 中,我创建了一个按钮。
I have another tab named country which contain a table for country list我有另一个名为 country 的选项卡,其中包含一个国家/地区列表表格
I have another tab also named car which contain a table for car list我有另一个名为 car 的选项卡,其中包含一个汽车列表表
Now i want to create a file "output.txt" which should create with some code from both tabs (country and vehicle )when click Generate code button .现在我想创建一个文件“output.txt”,当单击“生成代码”按钮时,它应该使用来自两个选项卡(国家和车辆)的一些代码创建。
My output.txt format :我的output.txt格式:
*from sheet1 Country*/
VAR const US[] =
{
0x0,/*binary 00000*/
0xB,/*binary 01011*/
0x3,/*binary 00011*/
0x3,/*binary 00011*/
0xB,/*binary 01011*/
1xB /*binary 11011*/
};
//need to crate hexa array for Uk,france,brazil and india
VAR DefaultCountry[] =
{
invalid,
UK,
Brazil,
Brazil,
UK,
India
};
/* from sheet2 car */
VAR const polo[] =
{
};
//need to crate hexa array for BMW,i20,Swift and wagnor
VAR DefaultCAR[] =
{
invalid,
BMW,
Swift,
Swift,
BMW,
Wagnor
}
excelsheet.txt format : excelsheet.txt格式:
const exceldetails[Maxindex] =
{
/* index 0 */
/* index 1 */
{
{ UK, India, brazil,eMaxNoOfcountry, eMaxNoOfcountry},
{BMW, Wagnor, Swift,eMaxNoOfcar,eMaxNoOfcar },
index1,
},
/*index 2*/
etc..
};
If the column has "-" , it should take 0 value and if it is integer , it should take 1 value and print the hexa value and binary value both如果列有 "-" ,它应该取 0 值,如果它是整数,它应该取 1 值并打印六进制值和二进制值
eg: for country index 0 : - - - - - => binary : 00000 => hexa : 0x0 index 1 : - 1 - 3 2 => binary : 01011 => hexa : 0xB例如:对于国家索引 0:- - - - - => 二进制:00000 => 六:0x0 索引 1:- 1 - 3 2 => 二进制:01011 => 六:0xB
Array name : VAR const US[],france etc.. VAR const polo[],swift etc..数组名称: VAR const US[],france 等.. VAR const polo[],swift 等..
If the column contain 1 , It is default value and print the default value column name for each index in array如果列包含 1 ,则为默认值并打印数组中每个索引的默认值列名
array name : VAR DefaultCountry[],VAR DefaultCAR[])数组名称: VAR DefaultCountry[],VAR DefaultCAR[])
Create another file "exceldetails.txt" and write the order of each country and car details in array .创建另一个文件“exceldetails.txt”并将每个国家的顺序和汽车详细信息写入数组。 If "-" present take as eMaxNoOf.
如果出现“-”则作为 eMaxNoOf。
array name : exceldetails[Maxindex])数组名称: exceldetails[Maxindex])
How to do this ?这该怎么做 ? Any help ?
有什么帮助吗? Any Reference also be helpful .
任何参考也有帮助。 How to use one button for taking table values from multi tabs?
如何使用一键从多选项卡中获取表值?
I give you a little snippet code that doesn't answer all your question but only when you convert decimal value in binary and in hex.我给你一个小片段代码,它不能回答你所有的问题,但只有当你将十进制值转换为二进制和十六进制时。 I don't understood good all what you want
我不明白你想要什么
Sub test()
'binary code and hex code
With Application.WorksheetFunction ' with this row you can use the functions Dec2Bin, Dec2Hex
'convert decimal in binary
Cells(1, 1) = .Dec2Bin(Cells(1, 2)) ' input 3 -> out: 11
'convert binary in hex
Cells(2, 1) = .Dec2Hex(Cells(2, 2)) ' input 11 -> out B
End With
End Sub
this is the snippet code where you can create and write into file txt这是您可以在其中创建和写入文件 txt 的片段代码
Sub test()
'create and write into file txt
'when you execute again the macro the file is overwritten
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("yourPath\MyFile.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
End Sub
I created two macro so you can try every single macro.我创建了两个宏,因此您可以尝试每个宏。 You have to create an only macro where there is all the code...
您必须创建一个唯一的宏,其中包含所有代码...
hope this helps希望这可以帮助
EDIT to answer your commento If you want work into sheet below there is an example编辑以回答您的评论如果您想在下面的工作表中工作,则有一个示例
Sub test()
Dim sh1, sh2 As Worksheet
Dim i, r, numRows, numColumns As Long
'set sh1 and the works it
Set sh1 = Sheets("Country") ' sheet name
'count how many rows there are into sheet1
'numRows = sh1.Range("A:A").Cells.SpecialCells(xlCellTypeContants).Count
numRows = sh1.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows
'count how many columns there are into sheet1
numColumns = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns
With sh1
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then
'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...
End If
Next i
Next j
End With
'----repeat operation for the sheet2
'set sh2 and the works it
Set sh2 = Sheets("car") ' sheet name
'count how many rows there are into sheet2
numRows = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows
'count how many columns there are into sheet2
numColumns = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns
With sh2
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then
'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...
End If
Next i
Next j
End With
End Sub
There are two for loop because One use the columns and the other the rows...有两个 for 循环,因为一个使用列,另一个使用行......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.