Spc function
Used with the Print # statement or the Print method to position output.
Syntax
Spc(n)
The required n argument is the number of spaces to insert before displaying or printing the next expression in a list.
Remarks
If n is less than the output line width, the next print position immediately follows the number of spaces printed. If n is greater than the output line width, Spc calculates the next print position using the formula: currentprintposition + (nModwidth).
For example, if the current print position is 24, the output line width is 80, and you specify Spc(90), the next print will start at position 34 (current print position + the remainder of 90/80). If the difference between the current print position and the output line width is less than n (or nModwidth), the Spc function skips to the beginning of the next line and generates spaces equal to n - (width - currentprintposition).
Note
Make sure your tabular columns are wide enough to accommodate wide letters.
When you use the Print method with a proportionally spaced font, the width of space characters printed by using the Spc function is always an average of the width of all characters in the point size for the chosen font. However, there is no correlation between the number of characters printed and the number of fixed-width columns those characters occupy. For example, the uppercase letter W occupies more than one fixed-width column and the lowercase letter i occupies less than one fixed-width column.
Example
This example uses the Spc function to position output in a file and in the Immediate window.
' The Spc function can be used with the Print # statement.
Open "TESTFILE" For Output As #1 ' Open file for output.
Print #1, "10 spaces between here"; Spc(10); "and here."
Close #1 ' Close file.
The following statement causes the text to be printed in the Immediate window (by using the Print method), preceded by 30 spaces.
Debug.Print Spc(30); "Thirty spaces later..."
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기