VBA-如何参考“文件名”中其他打开的工作簿的“单元格值”进行“另存为”

时间:2019-02-23 05:05:27

标签: excel vba

需要帮助创建VBA代码以参考“文件名”中其他打开的工作簿的“单元格值”进行“另存为”。

1 个答案:

答案 0 :(得分:-1)

不确定您是否真的想保持数据文件打开,否则,可以使用ExecuteExcel4Macro方法:

class Customer(models.Model):
customer_bank        = models.ForeignKey('Bank', on_delete=models.SET_NULL,related_name='coustmer_bank' ,null=True)
customer_branch      = models.ForeignKey('Branch', on_delete=models.SET_NULL,related_name='coustmer_branch',null=True)
booking_id           = models.CharField(max_length=120, blank= True,default=increment_booking_number)
identity_type        = models.ForeignKey('IdentityType',on_delete=models.SET_NULL,related_name='identity_type',null=True)
identity_or_passport_number   = models.CharField(max_length=20)
bank_account_no      = models.CharField(max_length=15)
Done                 = models.BooleanField(default=False)
booking_date_time    = models.DateTimeField(auto_now_add=True, auto_now=False)
Entrance_date_time   = models.DateTimeField(auto_now_add=False, auto_now=True)# Must be modified to work with Entrance Date and Time

def __str__(self):
    return self.booking_id

def get_booking_id(self):
    bank_number = self.bank_number
    branch_number = self.branch_number
    id = # logic for calculating boking ID from bank_number, branch_number and other fields accessible from self.<field_name>
    return id

def save(self, *args, **kwargs):
    self.booking_id = self.get_booking_id()
    super(Customer, self).save(*args, **kwargs)

这是我的功能:

monthname = ExecuteExcel4Macro("'C:\FolderPath\[Data.xlsx]Sheet1'!" & _
            Range("A1").Address(, , xlR1C1))

测试功能:

'### The xl file can be closed or open ###
Function getValueInWB( _
                        folderPath As String, _
                        fileName As String, _
                        shName As String, _
                        rAdd As String _
                        )

    Dim str As String

    str = "'" & folderPath & _
            "[" & fileName & "]" & _
            shName & "'!" & _
            Range(rAdd).Address(, , xlR1C1)

    getValueInWB = ExecuteExcel4Macro(str)

End Function