如何获取UserForm的Application对象的引用?

时间:2018-02-21 04:52:59

标签: excel vba excel-vba

如果我想写一个UserForm相对于显示它的Application对象定位Sub PositionForm(WhichForm as Object) WhichForm.Left = <WhichForm Application Object>.Left End Sub ,我该如何去做呢?

我想写一个像这样的子:

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

public class ExcelHSSFXSSFProtectedSheetPassword {

 public static void main(String[] args) throws Exception {

  Workbook hssfworkbook = new HSSFWorkbook();

  Sheet sheet = hssfworkbook.createSheet();
  sheet.protectSheet("passwordExcel"); 

  short pwdHash = ((HSSFSheet)sheet).getPassword(); 
System.out.println(pwdHash);

  hssfworkbook.close();


  Workbook xssfworkbook = new XSSFWorkbook();

  sheet = xssfworkbook.createSheet();
  sheet.protectSheet("passwordExcel"); 

  byte[] pwdBytes = ((XSSFSheet)sheet).getCTWorksheet().getSheetProtection().getPassword();
  pwdHash = java.nio.ByteBuffer.wrap(pwdBytes).order(java.nio.ByteOrder.BIG_ENDIAN).getShort();
System.out.println(pwdHash);

  xssfworkbook.close();

 }

}

我知道有很多解决方法。我有兴趣知道是否有办法获得该参考。

1 个答案:

答案 0 :(得分:1)

在Excel中

以下工作:

Sub PositionForm(WhichForm As Object)
    WhichForm.Left = Application.Left
End Sub
从任何UserForm代码调用

Private Sub CommandButton2_Click()

   ... any code

    PositionForm Me

    ... any code

End Sub