Home > Software engineering >  I want to write a vb modified cell line height and column width (in CM) of small programs
I want to write a vb modified cell line height and column width (in CM) of small programs

Time:10-25

 

Option Explicit
Private Sub cmd1_Click ()
Dim xlsxapp As Excel. Application
Dim xlsxbook As Excel. The Workbook
Dim xlsxsheet As Excel. The Worksheet
Dim sheetname, excelpath As String
Dim rowheight, columnwidth As Single 'statement b for Single precision
The Set xlsxapp=CreateObject (" Excel. Application ") 'create Excel object
Xlsxapp. Visible=False 'set the EXCEL object Visible or invisible
Sheetname=txt3. Text
Excelpath=txt4. Text
The Debug. Print excelpath
The Debug. Print sheetname
The Set xlsxbook=xlsxapp. Workbooks. Open (excelpath) 'Open the EXCEL workpiece book file already exists, must Open the EXCEL with application a folder
The Set xlsxsheet=xlsxbook. Worksheets (sheetname)
Xlsxbook. Worksheets (sheetname). Activate
MsgBox "please select a need to change the column width cross cell line height"
If txt1. Text & lt;> "" Then
Rowheight=CSng (txt1. Text) 'the text1. The value of the Text is converted into a single precision number and assign a value to the rowheight
Rowheight=rowheight * 28.45
Xlsxbook. Xlsxsheet. Rows (ActiveCell.) rowheight=rowheight
End the If
If txt2. Text & lt;> "" Then
Columnwidth=CSng (txt2. Text)
Columnwidth columnwidth *=83.8/1.9
Xlsxbook. Xlsxsheet. Rows (ActiveCell.) columnwidth=columnwidth
End the If
The Set xlsxbook=Nothing
The Set xlsxsheet=Nothing
Xlsxapp. Quit
End Sub
Private Sub txt4_Click ()
CommonDialog1. Action=1
CommonDialog1. Filter="EXCEL (*. XLSX) | (*. XLSX)"
Txt4. Text=CommonDialog1. FileName
End Sub

Which always xlsxbook. Xlsxsheet. Rows (ActiveCell.) columnwidth=columnwidth that there is an error code, strives for the guidance, the couple!

CodePudding user response:

I work with form get file path name and table name! Vb can automatically get an open path and activation of excel table work table name?
In addition, vb and vba syntax what are not the same!

CodePudding user response:

Your ActiveCell no assignment!

reference 1st floor u012394283 response:
I work with form get file path name and table name! Vb can automatically get an open path and activation of excel table work table name?
In addition, vb and vba syntax what are not the same!

It seems that your code is quoted the Office object library,
Quotes, basically no difference to write,

CodePudding user response:

reference 1st floor u012394283 response:
... Vb can automatically get an open path and activation of excel table work table name?
In addition, vb and vba syntax what are not the same!

Create objects, and then use Excel. Application object invocation. Workbooks. The Open ()
The first parameter to the full path to the file transfer,
Files in disk any directory can be open, don't have to be put in the application directory,

CodePudding user response:

No copy? The meaning of activecell cell is activity? Need to copy?
Create objects, and then use Excel. Application object invocation. Workbooks. The Open ()
The first parameter to the full path to the file transfer,
Files in disk any directory can be open, don't have to be put in the application directory,
Yeah! I use commondiaog access path to the file name, then use a string file path name, there is a better way, strives for the correct code?

CodePudding user response:

reference 4 floor u012394283 response:
no copy? The meaning of activecell cell is activity? Need to copy?
.

You should make it clear: the variable name (identifier) and the difference between "objects" ah...
Xlsxbook. Xlsxsheet. Rows ( ActiveCell ). Columnwidth=columnwidth
Here, ActiveCell is variable names, rather than the object,
And the Rows () need parameter is also wrong object,
Xlsxbook. Xlsxsheet. Rows () "to return the result" is an object (reference)!

The way you open the workbook, in general, basically is used, what is not "better",

By the way, your Private Sub txt4_Click () statement, line 1 and line 2 want to swap the location,
If not, what is your current line 2 is redundant,

CodePudding user response:

I just see your comments in writing "open the EXCEL workpiece book file already exists, must open the EXCEL with application a folder"

. To tell you that the Open () there to preach the full path of the document, which can put casually, without "must be a folder with the application,"

CodePudding user response:

Reference
which always xlsxbook. Xlsxsheet. Rows (ActiveCell.) columnwidth=columnwidth that there is an error code, strives for the guidance, the couple!


May be the following problems:
1, now that you have the right xlsxsheet assignment, don't use "adjective", direct use of xlsxsheet. Rows (... )
Method and columnwidth mismatch, 2 Rows, Row==& gt; Rowheight Columns==& gt; Columnwidth
3, if the code is not in the excel environment, should be can not directly use ActiveCell, and should be xlsxapp. ActiveCell
  •  Tags:  
  • VBA
  • Related